Skip to content

Commit

Permalink
test(InputSwitch): update test and resolve Todo regarding use of RTL …
Browse files Browse the repository at this point in the history
…fireEvent
  • Loading branch information
LMulvey authored and julianguyen committed Oct 13, 2022
1 parent d05136d commit 72f396e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions client/app/components/Input/__tests__/InputSwitch.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import { render, screen, fireEvent } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { InputMocks } from 'mocks/InputMocks';

Expand Down Expand Up @@ -28,22 +28,19 @@ describe('InputSwitch', () => {
});

describe('with keyboard', () => {
it('toggles correctly', () => {
it('toggles correctly', async () => {
render(component);
const inputSwitch = screen.getByRole('switch');
const user = await userEvent.setup();

expect(screen.getByRole('checkbox')).not.toBeChecked();

/**
* TODO: Follow up on `await userEvent.type(inputSwitch, '{enter}')` in v12.1.7.
* Temporarily including `fireEvent` from RTL, for which the switch must have focus first:
* https://github.com/testing-library/react-testing-library/issues/376#issuecomment-541242684
*/
fireEvent.focus(inputSwitch);
fireEvent.keyDown(inputSwitch, { key: 'Enter' });
await user.tab();
expect(inputSwitch).toHaveFocus();
await user.keyboard('{Enter}');
expect(screen.getByRole('checkbox')).toBeChecked();

fireEvent.keyDown(inputSwitch, { key: 'Enter' });
await user.keyboard('{Enter}');
expect(screen.getByRole('checkbox')).not.toBeChecked();
});
});
Expand Down

0 comments on commit 72f396e

Please sign in to comment.