Skip to content

Commit

Permalink
Apply same changes to FormFileUpload
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed May 3, 2022
1 parent d29a22f commit 79bdd56
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions packages/components/src/form-file-upload/test/index.js
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -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 <input type="file"> 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( {
Expand All @@ -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( <FormFileUpload>My Upload Button</FormFileUpload> );

Expand All @@ -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(
<FormFileUpload onChange={ onChange }>
My Upload Button
</FormFileUpload>
Expand All @@ -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(
<FormFileUpload
onClick={ jest.fn( ( e ) => ( e.target.value = '' ) ) }
onChange={ onChange }
Expand Down

0 comments on commit 79bdd56

Please sign in to comment.