From 79bdd562a4da27f9fd1d81e1bb12cb7903d2c840 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Tue, 3 May 2022 16:19:37 +0200 Subject: [PATCH] Apply same changes to `FormFileUpload` --- .../src/form-file-upload/test/index.js | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/components/src/form-file-upload/test/index.js b/packages/components/src/form-file-upload/test/index.js index 0be360f73d9a7..6e7e86547d2fd 100644 --- a/packages/components/src/form-file-upload/test/index.js +++ b/packages/components/src/form-file-upload/test/index.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { render as RTLrender, screen } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; /** @@ -14,15 +14,9 @@ import FormFileUpload from '../'; */ const { File } = window; -function render( jsx ) { - return { - user: userEvent.setup( { - // Avoids timeout errors (https://github.com/testing-library/user-event/issues/565#issuecomment-1064579531). - delay: null, - } ), - ...RTLrender( jsx ), - }; -} +const user = userEvent.setup( { + advanceTimers: jest.advanceTimersByTime, +} ); // @testing-library/user-event considers changing to a string as a change, but it do not occur on real browsers, so the comparisons will be against this result const fakePath = expect.objectContaining( { @@ -32,6 +26,15 @@ const fakePath = expect.objectContaining( { } ); describe( 'FormFileUpload', () => { + beforeEach( () => { + jest.useFakeTimers(); + } ); + + afterEach( () => { + jest.runOnlyPendingTimers(); + jest.useRealTimers(); + } ); + it( 'should show an Icon Button and a hidden input', () => { render( My Upload Button ); @@ -44,7 +47,7 @@ describe( 'FormFileUpload', () => { it( 'should not fire a change event after selecting the same file', async () => { const onChange = jest.fn(); - const { user } = render( + render( My Upload Button @@ -67,7 +70,7 @@ describe( 'FormFileUpload', () => { it( 'should fire a change event after selecting the same file if the value was reset in between', async () => { const onChange = jest.fn(); - const { user } = render( + render( ( e.target.value = '' ) ) } onChange={ onChange }