-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathCheckbox.test.js
More file actions
33 lines (26 loc) · 1.05 KB
/
Copy pathCheckbox.test.js
File metadata and controls
33 lines (26 loc) · 1.05 KB
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
import { render, screen, fireEvent } from '@testing-library/react';
import App from './App';
test('should start with enabled button and unchecked checkbox', () => {
render(<App />);
//
const button = screen.getByRole('button', {name: 'Change to blue'})
// https://github.com/testing-library/jest-dom
// expect API: https://jestjs.io/docs/expect
expect(button).toBeEnabled();
const checkbox = screen.getByRole('checkbox')
// asserting that the checkbox is starting unchecked
expect(checkbox).not.toBeChecked();
})
test('should disable and enable checkbox on click', () => {
render(<App />);
const button = screen.getByRole('button', {name: 'Change to blue'})
// https://github.com/testing-library/jest-dom
// expect API: https://jestjs.io/docs/expect
const checkbox = screen.getByRole('checkbox', {name: 'Disable button'});
// asserting that the checkbox is starting unchecked
expect(checkbox).not.toBeChecked();
fireEvent.click(checkbox);
expect(button).toBeDisabled();
fireEvent.click(checkbox);
expect(checkbox).toBeEnabled();
})