@@ -8,15 +8,15 @@ beforeEach(() => {
8
8
test ( 'query can return null' , ( ) => {
9
9
const {
10
10
queryByLabelText,
11
- queryBySelectText ,
11
+ queryByDisplayValue ,
12
12
queryByPlaceholderText,
13
13
queryByText,
14
14
queryByTestId,
15
15
queryByAltText,
16
16
} = render ( '<div />' )
17
17
expect ( queryByTestId ( 'LucyRicardo' ) ) . toBeNull ( )
18
18
expect ( queryByLabelText ( 'LucyRicardo' ) ) . toBeNull ( )
19
- expect ( queryBySelectText ( 'LucyRicardo' ) ) . toBeNull ( )
19
+ expect ( queryByDisplayValue ( 'LucyRicardo' ) ) . toBeNull ( )
20
20
expect ( queryByPlaceholderText ( 'LucyRicardo' ) ) . toBeNull ( )
21
21
expect ( queryByText ( 'LucyRicardo' ) ) . toBeNull ( )
22
22
expect ( queryByAltText ( 'LucyRicardo' ) ) . toBeNull ( )
@@ -25,27 +25,18 @@ test('query can return null', () => {
25
25
test ( 'get throws a useful error message' , ( ) => {
26
26
const {
27
27
getByLabelText,
28
- getBySelectText ,
28
+ getByDisplayValue ,
29
29
getByPlaceholderText,
30
30
getByText,
31
31
getByTestId,
32
32
getByAltText,
33
33
getByTitle,
34
- getByValue,
35
34
getByRole,
36
35
} = render ( '<div />' )
37
36
expect ( ( ) => getByLabelText ( 'LucyRicardo' ) )
38
37
. toThrowErrorMatchingInlineSnapshot ( `
39
38
"Unable to find a label with the text of: LucyRicardo
40
39
41
- [36m<div>[39m
42
- [36m<div />[39m
43
- [36m</div>[39m"
44
- ` )
45
- expect ( ( ) => getBySelectText ( 'LucyRicardo' ) )
46
- . toThrowErrorMatchingInlineSnapshot ( `
47
- "Unable to find a <select> element with the selected option's text: LucyRicardo
48
-
49
40
[36m<div>[39m
50
41
[36m<div />[39m
51
42
[36m</div>[39m"
@@ -86,7 +77,8 @@ test('get throws a useful error message', () => {
86
77
[36m<div />[39m
87
78
[36m</div>[39m"
88
79
` )
89
- expect ( ( ) => getByValue ( 'LucyRicardo' ) ) . toThrowErrorMatchingInlineSnapshot ( `
80
+ expect ( ( ) => getByDisplayValue ( 'LucyRicardo' ) )
81
+ . toThrowErrorMatchingInlineSnapshot ( `
90
82
"Unable to find an element with the value: LucyRicardo.
91
83
92
84
[36m<div>[39m
@@ -285,20 +277,20 @@ test('query/get title element of SVG', () => {
285
277
} )
286
278
287
279
test ( 'query/get element by its value' , ( ) => {
288
- const { getByValue , queryByValue } = render ( `
280
+ const { getByDisplayValue , queryByDisplayValue } = render ( `
289
281
<div>
290
282
<input placeholder="name" type="text"/>
291
283
<input placeholder="lastname" type="text" value="Norris"/>
292
284
<input placeholder="email" type="text"/>
293
285
</div>
294
286
` )
295
287
296
- expect ( getByValue ( 'Norris' ) . placeholder ) . toEqual ( 'lastname' )
297
- expect ( queryByValue ( 'Norris' ) . placeholder ) . toEqual ( 'lastname' )
288
+ expect ( getByDisplayValue ( 'Norris' ) . placeholder ) . toEqual ( 'lastname' )
289
+ expect ( queryByDisplayValue ( 'Norris' ) . placeholder ) . toEqual ( 'lastname' )
298
290
} )
299
291
300
292
test ( 'query/get select by text with the default option selected' , ( ) => {
301
- const { getBySelectText , queryBySelectText } = render ( `
293
+ const { getByDisplayValue , queryByDisplayValue } = render ( `
302
294
<select id="state-select">
303
295
<option value="">State</option>
304
296
<option value="AL">Alabama</option>
@@ -307,12 +299,12 @@ test('query/get select by text with the default option selected', () => {
307
299
</select>
308
300
` )
309
301
310
- expect ( getBySelectText ( 'State' ) . id ) . toEqual ( 'state-select' )
311
- expect ( queryBySelectText ( 'State' ) . id ) . toEqual ( 'state-select' )
302
+ expect ( getByDisplayValue ( 'State' ) . id ) . toEqual ( 'state-select' )
303
+ expect ( queryByDisplayValue ( 'State' ) . id ) . toEqual ( 'state-select' )
312
304
} )
313
305
314
306
test ( 'query/get select by text with one option selected' , ( ) => {
315
- const { getBySelectText , queryBySelectText } = render ( `
307
+ const { getByDisplayValue , queryByDisplayValue } = render ( `
316
308
<select id="state-select">
317
309
<option value="">State</option>
318
310
<option value="AL">Alabama</option>
@@ -321,12 +313,12 @@ test('query/get select by text with one option selected', () => {
321
313
</select>
322
314
` )
323
315
324
- expect ( getBySelectText ( 'Alaska' ) . id ) . toEqual ( 'state-select' )
325
- expect ( queryBySelectText ( 'Alaska' ) . id ) . toEqual ( 'state-select' )
316
+ expect ( getByDisplayValue ( 'Alaska' ) . id ) . toEqual ( 'state-select' )
317
+ expect ( queryByDisplayValue ( 'Alaska' ) . id ) . toEqual ( 'state-select' )
326
318
} )
327
319
328
320
test ( 'query/get select by text with multiple options selected' , ( ) => {
329
- const { getBySelectText , queryBySelectText } = render ( `
321
+ const { getByDisplayValue , queryByDisplayValue } = render ( `
330
322
<select multiple id="state-select">
331
323
<option value="">State</option>
332
324
<option selected value="AL">Alabama</option>
@@ -335,8 +327,8 @@ test('query/get select by text with multiple options selected', () => {
335
327
</select>
336
328
` )
337
329
338
- expect ( getBySelectText ( 'Alabama' ) . id ) . toEqual ( 'state-select' )
339
- expect ( queryBySelectText ( 'Alaska' ) . id ) . toEqual ( 'state-select' )
330
+ expect ( getByDisplayValue ( 'Alabama' ) . id ) . toEqual ( 'state-select' )
331
+ expect ( queryByDisplayValue ( 'Alaska' ) . id ) . toEqual ( 'state-select' )
340
332
} )
341
333
342
334
describe ( 'query by test id' , ( ) => {
@@ -374,7 +366,7 @@ test('getAll* matchers return an array', () => {
374
366
getAllByAltText,
375
367
getAllByTestId,
376
368
getAllByLabelText,
377
- getAllBySelectText ,
369
+ getAllByDisplayValue ,
378
370
getAllByPlaceholderText,
379
371
getAllByText,
380
372
getAllByRole,
@@ -412,8 +404,8 @@ test('getAll* matchers return an array', () => {
412
404
expect ( getAllByTestId ( 'poster' ) ) . toHaveLength ( 3 )
413
405
expect ( getAllByPlaceholderText ( / T h e R o c k / ) ) . toHaveLength ( 1 )
414
406
expect ( getAllByLabelText ( 'User Name' ) ) . toHaveLength ( 1 )
415
- expect ( getAllBySelectText ( 'Japanese cars' ) ) . toHaveLength ( 1 )
416
- expect ( getAllBySelectText ( / c a r s $ / ) ) . toHaveLength ( 2 )
407
+ expect ( getAllByDisplayValue ( 'Japanese cars' ) ) . toHaveLength ( 1 )
408
+ expect ( getAllByDisplayValue ( / c a r s $ / ) ) . toHaveLength ( 2 )
417
409
expect ( getAllByText ( / ^ w h e r e / i) ) . toHaveLength ( 1 )
418
410
expect ( getAllByRole ( / c o n t a i n e r / i) ) . toHaveLength ( 1 )
419
411
} )
@@ -423,11 +415,10 @@ test('getAll* matchers throw for 0 matches', () => {
423
415
getAllByAltText,
424
416
getAllByTestId,
425
417
getAllByLabelText,
426
- getAllBySelectText ,
418
+ getAllByDisplayValue ,
427
419
getAllByPlaceholderText,
428
420
getAllByText,
429
421
getAllByRole,
430
- getAllByDisplayValue,
431
422
} = render ( `
432
423
<div role="container">
433
424
<label>No Matches Please</label>
@@ -438,7 +429,7 @@ test('getAll* matchers throw for 0 matches', () => {
438
429
expect ( ( ) => getAllByAltText ( 'nope' ) ) . toThrow ( )
439
430
expect ( ( ) => getAllByLabelText ( 'nope' ) ) . toThrow ( )
440
431
expect ( ( ) => getAllByLabelText ( 'no matches please' ) ) . toThrow ( )
441
- expect ( ( ) => getAllBySelectText ( 'nope' ) ) . toThrow ( )
432
+ expect ( ( ) => getAllByDisplayValue ( 'nope' ) ) . toThrow ( )
442
433
expect ( ( ) => getAllByPlaceholderText ( 'nope' ) ) . toThrow ( )
443
434
expect ( ( ) => getAllByText ( 'nope' ) ) . toThrow ( )
444
435
expect ( ( ) => getAllByRole ( 'nope' ) ) . toThrow ( )
@@ -450,7 +441,7 @@ test('queryAll* matchers return an array for 0 matches', () => {
450
441
queryAllByAltText,
451
442
queryAllByTestId,
452
443
queryAllByLabelText,
453
- queryAllBySelectText ,
444
+ queryAllByDisplayValue ,
454
445
queryAllByPlaceholderText,
455
446
queryAllByText,
456
447
queryAllByRole,
@@ -461,7 +452,7 @@ test('queryAll* matchers return an array for 0 matches', () => {
461
452
expect ( queryAllByTestId ( 'nope' ) ) . toHaveLength ( 0 )
462
453
expect ( queryAllByAltText ( 'nope' ) ) . toHaveLength ( 0 )
463
454
expect ( queryAllByLabelText ( 'nope' ) ) . toHaveLength ( 0 )
464
- expect ( queryAllBySelectText ( 'nope' ) ) . toHaveLength ( 0 )
455
+ expect ( queryAllByDisplayValue ( 'nope' ) ) . toHaveLength ( 0 )
465
456
expect ( queryAllByPlaceholderText ( 'nope' ) ) . toHaveLength ( 0 )
466
457
expect ( queryAllByText ( 'nope' ) ) . toHaveLength ( 0 )
467
458
expect ( queryAllByRole ( 'nope' ) ) . toHaveLength ( 0 )
@@ -629,24 +620,18 @@ test('get throws a useful error message without DOM in Cypress', () => {
629
620
document . defaultView . Cypress = { }
630
621
const {
631
622
getByLabelText,
632
- getBySelectText,
633
623
getByPlaceholderText,
634
624
getByText,
635
625
getByTestId,
636
626
getByAltText,
637
627
getByTitle,
638
- getByValue ,
628
+ getByDisplayValue ,
639
629
} = render ( '<div />' )
640
630
expect ( ( ) =>
641
631
getByLabelText ( 'LucyRicardo' ) ,
642
632
) . toThrowErrorMatchingInlineSnapshot (
643
633
`"Unable to find a label with the text of: LucyRicardo"` ,
644
634
)
645
- expect ( ( ) =>
646
- getBySelectText ( 'LucyRicardo' ) ,
647
- ) . toThrowErrorMatchingInlineSnapshot (
648
- `"Unable to find a <select> element with the selected option's text: LucyRicardo"` ,
649
- )
650
635
expect ( ( ) =>
651
636
getByPlaceholderText ( 'LucyRicardo' ) ,
652
637
) . toThrowErrorMatchingInlineSnapshot (
@@ -664,7 +649,9 @@ test('get throws a useful error message without DOM in Cypress', () => {
664
649
expect ( ( ) => getByTitle ( 'LucyRicardo' ) ) . toThrowErrorMatchingInlineSnapshot (
665
650
`"Unable to find an element with the title: LucyRicardo."` ,
666
651
)
667
- expect ( ( ) => getByValue ( 'LucyRicardo' ) ) . toThrowErrorMatchingInlineSnapshot (
652
+ expect ( ( ) =>
653
+ getByDisplayValue ( 'LucyRicardo' ) ,
654
+ ) . toThrowErrorMatchingInlineSnapshot (
668
655
`"Unable to find an element with the value: LucyRicardo."` ,
669
656
)
670
657
} )
0 commit comments