-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckbox.test.tsx
59 lines (45 loc) · 2.01 KB
/
checkbox.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { createDOM } from '@builder.io/qwik/testing';
import { test, describe, expect } from 'vitest';
import { Checkbox } from './checkbox';
describe('<Checkbox />', () => {
test(`Should render primary variant`, async () => {
const { screen, render } = await createDOM();
await render(<Checkbox checked={true} variant="primary" />);
expect(screen.innerHTML).toMatchSnapshot();
});
test(`Should select / deselect (but doesn't)`, async () => {
const { screen, render, userEvent } = await createDOM();
await render(<Checkbox variant="action" />);
const selector = 'input[type="checkbox"]';
const checkbox = screen.querySelector(selector) as HTMLInputElement;
expect(checkbox.checked).toBeFalsy();
await userEvent(selector, 'click'); // doesn't work
// await userEvent(checkbox, 'click'); // doesn't work
// await userEvent('input[type="checkbox"]', 'click'); // doesn't work
// await userEvent(screen.querySelector(selector) as HTMLInputElement, 'click'); // doesn't work
expect(checkbox.checked).toBeTruthy();
});
// works!
test(`Should select / deselect`, async () => {
const { screen, render } = await createDOM();
await render(<Checkbox variant="action" />);
const selector = 'input[type="checkbox"]';
const checkbox = screen.querySelector(selector) as HTMLInputElement;
expect(checkbox.checked).toBeFalsy();
checkbox.click();
expect(checkbox.checked).toBeTruthy();
(screen.querySelector(selector) as HTMLInputElement).click();
expect(checkbox.checked).toBeFalsy();
checkbox.click();
expect(checkbox.checked).toBeTruthy();
});
test(`Should render indeterminate option `, async () => {
const { screen, render } = await createDOM();
await render(<Checkbox indeterminate />);
expect(screen.innerHTML).toMatchSnapshot();
const checkbox = screen.querySelector('input') as HTMLInputElement;
expect(checkbox.indeterminate).toBeTruthy();
checkbox.click();
expect(checkbox.checked).toBeTruthy();
});
});