@@ -52,16 +52,16 @@ test('can get elements by matching their text content', () => {
52
52
</span>
53
53
</div>
54
54
` )
55
- expect ( queryByText ( 'Currently showing' ) ) . toBeInTheDOM ( )
56
- expect ( queryByText ( 'Step 1 of 4' ) ) . toBeInTheDOM ( )
55
+ expect ( queryByText ( 'Currently showing' ) ) . toBeTruthy ( )
56
+ expect ( queryByText ( 'Step 1 of 4' ) ) . toBeTruthy ( )
57
57
} )
58
58
59
59
test ( 'matches case with RegExp matcher' , ( ) => {
60
60
const { queryByText} = render ( `
61
61
<span>STEP 1 of 4</span>
62
62
` )
63
- expect ( queryByText ( / S T E P 1 o f 4 / ) ) . toBeInTheDOM ( )
64
- expect ( queryByText ( / S t e p 1 o f 4 / ) ) . not . toBeInTheDOM ( )
63
+ expect ( queryByText ( / S T E P 1 o f 4 / ) ) . toBeTruthy ( )
64
+ expect ( queryByText ( / S t e p 1 o f 4 / ) ) . not . toBeTruthy ( )
65
65
} )
66
66
67
67
test ( 'get can get form controls by label text' , ( ) => {
@@ -120,7 +120,7 @@ test('totally empty label', () => {
120
120
test ( 'getByLabelText with aria-label' , ( ) => {
121
121
// not recommended normally, but supported for completeness
122
122
const { queryByLabelText} = render ( `<input aria-label="batman" />` )
123
- expect ( queryByLabelText ( / b a t / ) ) . toBeInTheDOM ( )
123
+ expect ( queryByLabelText ( / b a t / ) ) . toBeTruthy ( )
124
124
} )
125
125
126
126
test ( 'get element by its alt text' , ( ) => {
@@ -130,7 +130,9 @@ test('get element by its alt text', () => {
130
130
<img alt="finding nemo poster" src="/finding-nemo.png" />
131
131
</div>,
132
132
` )
133
- expect ( getByAltText ( / f i n .* n e m .* p o s t e r $ / i) . src ) . toBe ( 'http://localhost/finding-nemo.png' )
133
+ expect ( getByAltText ( / f i n .* n e m .* p o s t e r $ / i) . src ) . toBe (
134
+ 'http://localhost/finding-nemo.png' ,
135
+ )
134
136
} )
135
137
136
138
test ( 'query/get element by its title' , ( ) => {
@@ -161,14 +163,14 @@ test('query/get element by its value', () => {
161
163
162
164
test ( 'can get elements by data-testid attribute' , ( ) => {
163
165
const { queryByTestId} = render ( `<div data-testid="firstName"></div>` )
164
- expect ( queryByTestId ( 'firstName' ) ) . toBeInTheDOM ( )
165
- expect ( queryByTestId ( / f i r s t / ) ) . toBeInTheDOM ( )
166
- expect ( queryByTestId ( testid => testid === 'firstName' ) ) . toBeInTheDOM ( )
166
+ expect ( queryByTestId ( 'firstName' ) ) . toBeTruthy ( )
167
+ expect ( queryByTestId ( / f i r s t / ) ) . toBeTruthy ( )
168
+ expect ( queryByTestId ( testid => testid === 'firstName' ) ) . toBeTruthy ( )
167
169
// match should be exact, case-sensitive
168
- expect ( queryByTestId ( 'firstname' ) ) . not . toBeInTheDOM ( )
169
- expect ( queryByTestId ( 'first' ) ) . not . toBeInTheDOM ( )
170
- expect ( queryByTestId ( 'firstNamePlusMore' ) ) . not . toBeInTheDOM ( )
171
- expect ( queryByTestId ( 'first-name' ) ) . not . toBeInTheDOM ( )
170
+ expect ( queryByTestId ( 'firstname' ) ) . not . toBeTruthy ( )
171
+ expect ( queryByTestId ( 'first' ) ) . not . toBeTruthy ( )
172
+ expect ( queryByTestId ( 'firstNamePlusMore' ) ) . not . toBeTruthy ( )
173
+ expect ( queryByTestId ( 'first-name' ) ) . not . toBeTruthy ( )
172
174
} )
173
175
174
176
test ( 'getAll* matchers return an array' , ( ) => {
@@ -248,8 +250,8 @@ test('using jest helpers to assert element states', () => {
248
250
const { queryByTestId} = render ( `<span data-testid="count-value">2</span>` )
249
251
250
252
// other ways to assert your test cases, but you don't need all of them.
251
- expect ( queryByTestId ( 'count-value' ) ) . toBeInTheDOM ( )
252
- expect ( queryByTestId ( 'count-value1' ) ) . not . toBeInTheDOM ( )
253
+ expect ( queryByTestId ( 'count-value' ) ) . toBeTruthy ( )
254
+ expect ( queryByTestId ( 'count-value1' ) ) . not . toBeTruthy ( )
253
255
expect ( queryByTestId ( 'count-value' ) ) . toHaveTextContent ( '2' )
254
256
expect ( queryByTestId ( 'count-value' ) ) . not . toHaveTextContent ( '21' )
255
257
expect ( ( ) =>
@@ -258,21 +260,17 @@ test('using jest helpers to assert element states', () => {
258
260
259
261
// negative test cases wrapped in throwError assertions for coverage.
260
262
expect ( ( ) =>
261
- expect ( queryByTestId ( 'count-value' ) ) . not . toBeInTheDOM ( ) ,
263
+ expect ( queryByTestId ( 'count-value' ) ) . not . toBeTruthy ( ) ,
262
264
) . toThrowError ( )
263
265
expect ( ( ) =>
264
- expect ( queryByTestId ( 'count-value1' ) ) . toBeInTheDOM ( ) ,
266
+ expect ( queryByTestId ( 'count-value1' ) ) . toBeTruthy ( ) ,
265
267
) . toThrowError ( )
266
268
expect ( ( ) =>
267
269
expect ( queryByTestId ( 'count-value' ) ) . toHaveTextContent ( '3' ) ,
268
270
) . toThrowError ( )
269
271
expect ( ( ) =>
270
272
expect ( queryByTestId ( 'count-value' ) ) . not . toHaveTextContent ( '2' ) ,
271
273
) . toThrowError ( )
272
-
273
- expect ( ( ) =>
274
- expect ( { thisIsNot : 'an html element' } ) . toBeInTheDOM ( ) ,
275
- ) . toThrowError ( )
276
274
} )
277
275
278
276
test ( 'using jest helpers to check element attributes' , ( ) => {
@@ -359,21 +357,21 @@ test('test the debug helper prints the dom state here', () => {
359
357
</div>`
360
358
361
359
const { getByText} = render ( Large ) // render large DOM which exceeds 7000 limit
362
- expect ( ( ) => expect ( getByText ( 'not present' ) ) . toBeInTheDOM ( ) ) . toThrowError ( )
360
+ expect ( ( ) => expect ( getByText ( 'not present' ) ) . toBeTruthy ( ) ) . toThrowError ( )
363
361
364
362
const Hello = `<div data-testid="debugging" data-otherid="debugging">
365
363
Hello World!
366
364
</div>`
367
365
const { getByTestId} = render ( Hello )
368
366
process . env . DEBUG_PRINT_LIMIT = 5 // user should see `...`
369
- expect ( ( ) => expect ( getByTestId ( 'not present' ) ) . toBeInTheDOM ( ) ) . toThrowError (
367
+ expect ( ( ) => expect ( getByTestId ( 'not present' ) ) . toBeTruthy ( ) ) . toThrowError (
370
368
/ \. \. \. / ,
371
369
)
372
370
373
371
const { getByLabelText} = render ( Hello )
374
372
process . env . DEBUG_PRINT_LIMIT = 10000 // user shouldn't see `...`
375
373
expect ( ( ) =>
376
- expect ( getByLabelText ( 'not present' ) ) . toBeInTheDOM ( / ^ ( (? ! \. \. \. ) .) * $ / ) ,
374
+ expect ( getByLabelText ( 'not present' ) ) . toBeTruthy ( / ^ ( (? ! \. \. \. ) .) * $ / ) ,
377
375
) . toThrowError ( )
378
376
379
377
//all good replacing it with old value
0 commit comments