@@ -9,11 +9,11 @@ test('renders correctly', () => {
99 // Idiom: no need to capture render output, as we will use `screen` for queries.
1010 render ( < App /> ) ;
1111
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 ()`
1313 // to clarify our intent.
1414 expect (
1515 screen . getByRole ( 'header' , { name : 'Sign in to Example App' } )
16- ) . toBeTruthy ( ) ;
16+ ) . toBeOnTheScreen ( ) ;
1717} ) ;
1818
1919/**
@@ -25,12 +25,11 @@ test('User can sign in successully with correct credentials', async () => {
2525 // Idiom: no need to capture render output, as we will use `screen` for queries.
2626 render ( < App /> ) ;
2727
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 ()`
2929 // to clarify our intent.
30- // Note: `.toBeTruthy()` is the preferred matcher for checking that elements are present.
3130 expect (
3231 screen . getByRole ( 'header' , { name : 'Sign in to Example App' } )
33- ) . toBeTruthy ( ) ;
32+ ) . toBeOnTheScreen ( ) ;
3433
3534 // Hint: we can use `getByLabelText` to find our text inputs using their labels.
3635 fireEvent . changeText ( screen . getByLabelText ( 'Username' ) , 'admin' ) ;
@@ -45,14 +44,14 @@ test('User can sign in successully with correct credentials', async () => {
4544 // already finished
4645 expect (
4746 await screen . findByRole ( 'header' , { name : 'Welcome admin!' } )
48- ) . toBeTruthy ( ) ;
47+ ) . toBeOnTheScreen ( ) ;
4948
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.
5150 expect (
5251 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 ( ) ;
5655} ) ;
5756
5857/**
@@ -72,7 +71,7 @@ test('User will see errors for incorrect credentials', async () => {
7271
7372 expect (
7473 screen . getByRole ( 'header' , { name : 'Sign in to Example App' } )
75- ) . toBeTruthy ( ) ;
74+ ) . toBeOnTheScreen ( ) ;
7675
7776 fireEvent . changeText ( screen . getByLabelText ( 'Username' ) , 'admin' ) ;
7877 fireEvent . changeText ( screen . getByLabelText ( 'Password' ) , 'qwerty123' ) ;
@@ -85,9 +84,9 @@ test('User will see errors for incorrect credentials', async () => {
8584
8685 expect (
8786 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 ( ) ;
9190} ) ;
9291
9392/**
@@ -98,7 +97,7 @@ test('User can sign in after incorrect attempt', async () => {
9897
9998 expect (
10099 screen . getByRole ( 'header' , { name : 'Sign in to Example App' } )
101- ) . toBeTruthy ( ) ;
100+ ) . toBeOnTheScreen ( ) ;
102101
103102 fireEvent . changeText ( screen . getByLabelText ( 'Username' ) , 'admin' ) ;
104103 fireEvent . changeText ( screen . getByLabelText ( 'Password' ) , 'qwerty123' ) ;
@@ -111,10 +110,10 @@ test('User can sign in after incorrect attempt', async () => {
111110 fireEvent . changeText ( screen . getByLabelText ( 'Password' ) , 'admin1' ) ;
112111 fireEvent . press ( screen . getByRole ( 'button' , { name : 'Sign In' } ) ) ;
113112
114- expect ( await screen . findByText ( 'Welcome admin!' ) ) . toBeTruthy ( ) ;
113+ expect ( await screen . findByText ( 'Welcome admin!' ) ) . toBeOnTheScreen ( ) ;
115114 expect (
116115 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 ( ) ;
120119} ) ;
0 commit comments