/** * @jest-environment jsdom */ import ReactDOM from 'react-dom'; import { act } from 'react-dom/test-utils'; import i18n, { useTranslate } from '..'; function Label() { const translate = useTranslate(); return translate( 'hook (%(lang)s)', { args: { lang: translate.localeSlug } } ); } describe( 'useTranslate()', () => { let container; beforeEach( () => { // reset to default locale act( () => { i18n.setLocale(); } ); // create container container = document.createElement( 'div' ); document.body.appendChild( container ); } ); afterEach( () => { // tear down the container ReactDOM.unmountComponentAtNode( container ); document.body.removeChild( container ); container = null; } ); test( 'renders a translated string', () => { // set some locale data i18n.setLocale( { '': { localeSlug: 'cs' }, 'hook (%(lang)s)': [ 'háček (%(lang)s)' ], } ); // render the Label component act( () => { ReactDOM.render(