Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test case
  • Loading branch information
talldan committed Jun 23, 2023
commit a6292f7e6a090468567811525fd09607638d6d59
21 changes: 21 additions & 0 deletions packages/components/src/confirm-dialog/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ describe( 'Confirm', () => {
expect( confirmDialog ).not.toBeInTheDocument();
expect( onConfirm ).toHaveBeenCalled();
} );

it( 'calls only the `onCancel` callback and not the `onConfirm` callback when the cancel button is submitted using the keyboard', async () => {
const user = userEvent.setup();

const onConfirm = jest.fn().mockName( 'onConfirm()' );
const onCancel = jest.fn().mockName( 'onCancel()' );

render(
<ConfirmDialog
onConfirm={ onConfirm }
onCancel={ onCancel }
>
Are you sure?
</ConfirmDialog>
);

await user.keyboard( '[Tab][Enter]' );

expect( onConfirm ).not.toHaveBeenCalled();
expect( onCancel ).toHaveBeenCalled();
} );
} );
} );

Expand Down