Skip to content

Commit

Permalink
Use createEvent()
Browse files Browse the repository at this point in the history
Co-authored-by: flootr <[email protected]>
  • Loading branch information
mirka and flootr committed Jan 28, 2023
1 parent 7893c96 commit ea95000
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/components/src/keyboard-shortcuts/test/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { fireEvent, render, screen } from '@testing-library/react';
import { createEvent, fireEvent, render, screen } from '@testing-library/react';

/**
* Internal dependencies
Expand All @@ -14,13 +14,16 @@ describe( 'KeyboardShortcuts', () => {
target: Parameters< typeof fireEvent >[ 0 ]
) {
[ 'keydown', 'keypress', 'keyup' ].forEach( ( eventName ) => {
const event = new window.Event( eventName, {
bubbles: true,
} );
// @ts-expect-error
event.keyCode = which;
// @ts-expect-error
event.which = which;
const event = createEvent(
eventName,
target,
{
bubbles: true,
keyCode: which,
which,
},
{ EventType: 'KeyboardEvent' }
);
fireEvent( target, event );
} );
}
Expand Down

0 comments on commit ea95000

Please sign in to comment.