Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebald committed Nov 16, 2022
1 parent 79fd58e commit 5e8eaa2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions packages/components/src/Checkbox/Checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ test('support default checked', () => {
</Checkbox>
</ThemeProvider>
);
const input = screen.getByTestId('checkbox');
expect(input).toHaveAttribute('aria-checked', 'true');

const input: HTMLInputElement = screen.getByTestId('checkbox');
expect(input.checked).toBeTruthy();

// Visible checkbox looks checked
const checkbox = getVisibleCheckbox();
Expand Down
18 changes: 9 additions & 9 deletions packages/components/src/Switch/Switch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const getSwitchParts = () => {
// eslint-disable-next-line testing-library/no-node-access
const thumb = track.lastChild!;

const input = screen.getByRole('switch');
const input: HTMLInputElement = screen.getByRole('switch');

return { label, input, container, track, thumb };
};
Expand Down Expand Up @@ -175,11 +175,11 @@ test('toggle switch per click', () => {

fireEvent.click(input);
expect(track).toHaveStyle(`background-color: orange`);
expect(input).toHaveAttribute('aria-checked', 'true');
expect(input.checked).toBeTruthy();

fireEvent.click(input);
expect(track).toHaveStyle(`background-color: blue`);
expect(input).toHaveAttribute('aria-checked', 'false');
expect(input.checked).toBeFalsy();
});

test('focus element and toggle switch per keyboard space', async () => {
Expand All @@ -198,13 +198,13 @@ test('focus element and toggle switch per keyboard space', async () => {
// eslint-disable-next-line testing-library/await-async-utils
waitFor(() => expect(track).toHaveStyle(`background-color: orange`));
// eslint-disable-next-line testing-library/await-async-utils
waitFor(() => expect(input).toHaveAttribute('aria-checked', 'true'));
waitFor(() => expect(input.checked).toBeTruthy());

user.keyboard('{space}');
// eslint-disable-next-line testing-library/await-async-utils
waitFor(() => expect(track).toHaveStyle(`background-color: blue`));
// eslint-disable-next-line testing-library/await-async-utils
waitFor(() => expect(input).toHaveAttribute('aria-checked', 'false'));
waitFor(() => expect(input.checked).toBeFalsy());
});

test('supports default checked', () => {
Expand All @@ -216,9 +216,9 @@ test('supports default checked', () => {

const { input } = getSwitchParts();

expect(input).toHaveAttribute('aria-checked', 'true');
expect(input.checked).toBeTruthy();
fireEvent.click(input);
expect(input).toHaveAttribute('aria-checked', 'false');
expect(input.checked).toBeFalsy();
});

test('supports controlled component usage', () => {
Expand All @@ -233,11 +233,11 @@ test('supports controlled component usage', () => {

fireEvent.click(input);
expect(onChange).toHaveBeenCalledWith(true);
expect(input).toHaveAttribute('aria-checked', 'true');
expect(input.checked).toBeTruthy();

fireEvent.click(input);
expect(onChange).toHaveBeenCalledWith(false);
expect(input).toHaveAttribute('aria-checked', 'false');
expect(input.checked).toBeFalsy();
});

test('forwards ref', () => {
Expand Down

0 comments on commit 5e8eaa2

Please sign in to comment.