Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrés Blanco committed May 3, 2024
1 parent 5c89795 commit f5312fb
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions client/landing/stepper/hooks/test/use-start-url.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @jest-environment jsdom
*/
import { renderHook } from '@testing-library/react';
import { useStartUrl } from '../use-start-url';

jest.mock( 'calypso/boot/locale', () => ( {
getLocaleFromQueryParam: jest.fn().mockReturnValue( 'fr' ),
getLocaleFromPathname: jest.fn().mockReturnValue( 'fr' ),
} ) );

jest.mock( '../../utils/path', () => ( {
getLoginUrl: jest.fn().mockReturnValue( 'https://example.com/login' ),
} ) );

describe( 'useStartUrl', () => {
beforeAll( () => {
Object.defineProperty( window, 'location', {
value: {
search: '?aff=123&vid=456',
replace: jest.fn(), // Ensure this is mocked if used in your code
href: '',
},
writable: true, // Allow this definition to be writable if needed later
} );
} );

it( 'should generate the correct start URL', () => {
// Use the hook and assert results
const { result } = renderHook( () => useStartUrl( 'test-flow' ) );

expect( result.current ).toBe(
'https://example.com/login&redirect_to=/setup/test-flow%3Flocale%3Dfr&vid=456&aff=123'
);
} );

afterAll( () => {
// Restore the original window.location object after all tests are done
jest.restoreAllMocks();
} );
} );

0 comments on commit f5312fb

Please sign in to comment.