Skip to content

Commit

Permalink
Improve unit tests for React 17 PR (#56004)
Browse files Browse the repository at this point in the history
* Wrap i18n locale with act in test

* Add fake timers to ETK tests
  • Loading branch information
noahtallen authored Sep 3, 2021
1 parent ae701d9 commit e10d909
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const STORE_KEY = 'automattic/wpcom-welcome-guide';

beforeAll( () => {
register();
jest.useFakeTimers(); // Required for wait-for-expect to work.
} );

let originalFetch;
Expand Down
12 changes: 8 additions & 4 deletions packages/i18n-calypso/test/use-translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ describe( 'useTranslate()', () => {

beforeEach( () => {
// reset to default locale
i18n.setLocale();
act( () => {
i18n.setLocale();
} );

// create container
container = document.createElement( 'div' );
Expand Down Expand Up @@ -68,9 +70,11 @@ describe( 'useTranslate()', () => {

test( 'rerenders after update of current locale translations', () => {
// set some locale data
i18n.setLocale( {
'': { localeSlug: 'cs' },
'hook (%(lang)s)': [ 'háček (%(lang)s)' ],
act( () => {
i18n.setLocale( {
'': { localeSlug: 'cs' },
'hook (%(lang)s)': [ 'háček (%(lang)s)' ],
} );
} );

// render the Label component
Expand Down

0 comments on commit e10d909

Please sign in to comment.