starts to provide a value', async () => {
( getLocaleData as jest.Mock ).mockImplementation( () => ( {
'': { language: 'es' },
} ) );
const unsubscribe = jest.fn();
( subscribe as jest.Mock ).mockImplementation( () => {
return unsubscribe();
} );
const { result, rerender } = renderHook( () => useLocale(), {
wrapper: ( props ) => ,
} );
expect( result.current ).toBe( 'es' );
rerender( { localeSlug: 'ar' } );
expect( unsubscribe ).toHaveBeenCalled();
} );
} );
describe( 'withLocale', () => {
const TestComponent = withLocale( ( { locale } ) => current locale is: { locale }
);
it( 'returns "en" if there is no LocaleProvider', () => {
const { getByText } = render( );
expect( getByText( 'current locale is: en' ) ).toBeInTheDocument();
} );
it( 'returns the slug supplied to LocaleProvider', () => {
const { getByText } = render(
);
expect( getByText( 'current locale is: ja' ) ).toBeInTheDocument();
} );
it( 'returns the new locale when it changes', () => {
const { getByText, rerender } = render(
);
rerender(
);
expect( getByText( 'current locale is: ar' ) ).toBeInTheDocument();
} );
} );