@@ -9,11 +9,11 @@ test('renders correctly', () => {
9
9
// Idiom: no need to capture render output, as we will use `screen` for queries.
10
10
render ( < App /> ) ;
11
11
12
- // Idiom: `getBy*` queries are predicates by themselves, but we will use it with `expect().toBeTruthy ()`
12
+ // Idiom: `getBy*` queries are predicates by themselves, but we will use it with `expect().toBeOnTheScreen ()`
13
13
// to clarify our intent.
14
14
expect (
15
15
screen . getByRole ( 'header' , { name : 'Sign in to Example App' } )
16
- ) . toBeTruthy ( ) ;
16
+ ) . toBeOnTheScreen ( ) ;
17
17
} ) ;
18
18
19
19
/**
@@ -25,12 +25,11 @@ test('User can sign in successully with correct credentials', async () => {
25
25
// Idiom: no need to capture render output, as we will use `screen` for queries.
26
26
render ( < App /> ) ;
27
27
28
- // Idiom: `getBy*` queries are predicates by themselves, but we will use it with `expect().toBeTruthy ()`
28
+ // Idiom: `getBy*` queries are predicates by themselves, but we will use it with `expect().toBeOnTheScreen ()`
29
29
// to clarify our intent.
30
- // Note: `.toBeTruthy()` is the preferred matcher for checking that elements are present.
31
30
expect (
32
31
screen . getByRole ( 'header' , { name : 'Sign in to Example App' } )
33
- ) . toBeTruthy ( ) ;
32
+ ) . toBeOnTheScreen ( ) ;
34
33
35
34
// Hint: we can use `getByLabelText` to find our text inputs using their labels.
36
35
fireEvent . changeText ( screen . getByLabelText ( 'Username' ) , 'admin' ) ;
@@ -45,14 +44,14 @@ test('User can sign in successully with correct credentials', async () => {
45
44
// already finished
46
45
expect (
47
46
await screen . findByRole ( 'header' , { name : 'Welcome admin!' } )
48
- ) . toBeTruthy ( ) ;
47
+ ) . toBeOnTheScreen ( ) ;
49
48
50
- // Idiom: use `queryBy*` with `expect().toBeFalsy ()` to assess that element is not present.
49
+ // Idiom: use `queryBy*` with `expect().not.toBeOnTheScreen ()` to assess that element is not present.
51
50
expect (
52
51
screen . queryByRole ( 'header' , { name : 'Sign in to Example App' } )
53
- ) . toBeFalsy ( ) ;
54
- expect ( screen . queryByLabelText ( 'Username' ) ) . toBeFalsy ( ) ;
55
- expect ( screen . queryByLabelText ( 'Password' ) ) . toBeFalsy ( ) ;
52
+ ) . not . toBeOnTheScreen ( ) ;
53
+ expect ( screen . queryByLabelText ( 'Username' ) ) . not . toBeOnTheScreen ( ) ;
54
+ expect ( screen . queryByLabelText ( 'Password' ) ) . not . toBeOnTheScreen ( ) ;
56
55
} ) ;
57
56
58
57
/**
@@ -72,7 +71,7 @@ test('User will see errors for incorrect credentials', async () => {
72
71
73
72
expect (
74
73
screen . getByRole ( 'header' , { name : 'Sign in to Example App' } )
75
- ) . toBeTruthy ( ) ;
74
+ ) . toBeOnTheScreen ( ) ;
76
75
77
76
fireEvent . changeText ( screen . getByLabelText ( 'Username' ) , 'admin' ) ;
78
77
fireEvent . changeText ( screen . getByLabelText ( 'Password' ) , 'qwerty123' ) ;
@@ -85,9 +84,9 @@ test('User will see errors for incorrect credentials', async () => {
85
84
86
85
expect (
87
86
screen . getByRole ( 'header' , { name : 'Sign in to Example App' } )
88
- ) . toBeTruthy ( ) ;
89
- expect ( screen . getByLabelText ( 'Username' ) ) . toBeTruthy ( ) ;
90
- expect ( screen . getByLabelText ( 'Password' ) ) . toBeTruthy ( ) ;
87
+ ) . toBeOnTheScreen ( ) ;
88
+ expect ( screen . getByLabelText ( 'Username' ) ) . toBeOnTheScreen ( ) ;
89
+ expect ( screen . getByLabelText ( 'Password' ) ) . toBeOnTheScreen ( ) ;
91
90
} ) ;
92
91
93
92
/**
@@ -98,7 +97,7 @@ test('User can sign in after incorrect attempt', async () => {
98
97
99
98
expect (
100
99
screen . getByRole ( 'header' , { name : 'Sign in to Example App' } )
101
- ) . toBeTruthy ( ) ;
100
+ ) . toBeOnTheScreen ( ) ;
102
101
103
102
fireEvent . changeText ( screen . getByLabelText ( 'Username' ) , 'admin' ) ;
104
103
fireEvent . changeText ( screen . getByLabelText ( 'Password' ) , 'qwerty123' ) ;
@@ -111,10 +110,10 @@ test('User can sign in after incorrect attempt', async () => {
111
110
fireEvent . changeText ( screen . getByLabelText ( 'Password' ) , 'admin1' ) ;
112
111
fireEvent . press ( screen . getByRole ( 'button' , { name : 'Sign In' } ) ) ;
113
112
114
- expect ( await screen . findByText ( 'Welcome admin!' ) ) . toBeTruthy ( ) ;
113
+ expect ( await screen . findByText ( 'Welcome admin!' ) ) . toBeOnTheScreen ( ) ;
115
114
expect (
116
115
screen . queryByRole ( 'header' , { name : 'Sign in to Example App' } )
117
- ) . toBeFalsy ( ) ;
118
- expect ( screen . queryByLabelText ( 'Username' ) ) . toBeFalsy ( ) ;
119
- expect ( screen . queryByLabelText ( 'Password' ) ) . toBeFalsy ( ) ;
116
+ ) . not . toBeOnTheScreen ( ) ;
117
+ expect ( screen . queryByLabelText ( 'Username' ) ) . not . toBeOnTheScreen ( ) ;
118
+ expect ( screen . queryByLabelText ( 'Password' ) ) . not . toBeOnTheScreen ( ) ;
120
119
} ) ;
0 commit comments