@@ -37,38 +37,38 @@ Nothing fancy. `CustomButton` is a component with a prop passed in. We're intere
37
37
``` jsx
38
38
// CustomButton.test.jsx
39
39
40
- import { vi } from ' vitest'
40
+ import { vi , describe , it , expect } from ' vitest'
41
41
import { render , screen } from " @testing-library/react" ;
42
42
import userEvent from " @testing-library/user-event" ;
43
43
import CustomButton from " ./CustomButton" ;
44
44
45
45
describe (" CustomButton" , () => {
46
- it (" should render a button with the text 'Click me'" , () => {
47
- render (< CustomButton onClick= {() => {}} / > );
46
+ it (" should render a button with the text 'Click me'" , () => {
47
+ render (< CustomButton onClick= {() => {}} / > );
48
48
49
- const button = screen .getByRole (" button" , { name: " Click me" });
49
+ const button = screen .getByRole (" button" , { name: " Click me" });
50
50
51
- expect (button).toBeInTheDocument ();
52
- });
51
+ expect (button).toBeInTheDocument ();
52
+ });
53
53
54
- it (" should call the onClick function when clicked" , async () => {
55
- const onClick = vi .fn ();
56
- const user = userEvent .setup ()
57
- render (< CustomButton onClick= {onClick} / > );
54
+ it (" should call the onClick function when clicked" , async () => {
55
+ const onClick = vi .fn ();
56
+ const user = userEvent .setup ()
57
+ render (< CustomButton onClick= {onClick} / > );
58
58
59
- const button = screen .getByRole (" button" , { name: " Click me" });
59
+ const button = screen .getByRole (" button" , { name: " Click me" });
60
60
61
- await user .click (button);
61
+ await user .click (button);
62
62
63
- expect (onClick).toHaveBeenCalled ();
64
- });
63
+ expect (onClick).toHaveBeenCalled ();
64
+ });
65
65
66
- it (" should not call the onClick function when it isn't clicked" , async () => {
67
- const onClick = vi .fn ();
68
- render (< CustomButton onClick= {onClick} / > );
66
+ it (" should not call the onClick function when it isn't clicked" , async () => {
67
+ const onClick = vi .fn ();
68
+ render (< CustomButton onClick= {onClick} / > );
69
69
70
- expect (onClick).not .toHaveBeenCalled ();
71
- });
70
+ expect (onClick).not .toHaveBeenCalled ();
71
+ });
72
72
});
73
73
```
74
74
0 commit comments