1
1
import { Selector } from "testcafe" ;
2
- import { within , getAllByTestId , getByTestId } from "../../src" ;
2
+ import { within , screen } from "../../src" ;
3
3
4
4
fixture `within` . page `../../test-app/index.html` ;
5
5
@@ -30,18 +30,20 @@ test("still works after browser page reload", async (t) => {
30
30
const nested = await within ( "#nested" ) ;
31
31
await t . expect ( nested . getByText ( "Button Text" ) . exists ) . ok ( ) ;
32
32
33
- await t . eval ( ( ) => location . reload ( true ) ) ;
33
+ await t . eval ( ( ) => location . reload ( ) ) ;
34
34
await t . expect ( nested . getByText ( "Button Text" ) . exists ) . ok ( ) ;
35
35
} ) ;
36
36
37
37
test ( "works with nested selectors" , async ( t ) => {
38
38
await t
39
- . expect ( within ( getByTestId ( "nested" ) ) . getByText ( "Button Text" ) . exists )
39
+ . expect (
40
+ within ( screen . getByTestId ( "nested" ) ) . getByText ( "Button Text" ) . exists
41
+ )
40
42
. ok ( ) ;
41
43
} ) ;
42
44
43
45
test ( 'works with nested selector from "All" query with index - regex' , async ( t ) => {
44
- const nestedDivs = getAllByTestId ( / n e s t e d / ) ;
46
+ const nestedDivs = screen . getAllByTestId ( / n e s t e d / ) ;
45
47
await t . expect ( nestedDivs . count ) . eql ( 2 ) ;
46
48
47
49
const nested = within ( nestedDivs . nth ( 1 ) ) ;
@@ -54,15 +56,15 @@ test('works with nested selector from "All" query with index - regex', async (t)
54
56
} ) ;
55
57
56
58
test ( 'works with nested selector from "All" query with index - exact:false' , async ( t ) => {
57
- const nestedDivs = getAllByTestId ( "nested" , { exact : false } ) ;
59
+ const nestedDivs = screen . getAllByTestId ( "nested" , { exact : false } ) ;
58
60
await t . expect ( nestedDivs . count ) . eql ( 2 ) ;
59
61
const nested = await within ( nestedDivs . nth ( 0 ) ) ;
60
62
61
63
await t . expect ( nested . getByText ( "Button Text" ) . exists ) . ok ( ) ;
62
64
} ) ;
63
65
64
66
test ( 'works with nested selector from "All" query with index - function' , async ( t ) => {
65
- const nestedDivs = getAllByTestId ( ( _content , element ) =>
67
+ const nestedDivs = screen . getAllByTestId ( ( _content , element ) =>
66
68
element . getAttribute ( "data-testid" ) ! . startsWith ( "nested" )
67
69
) ;
68
70
await t . expect ( nestedDivs . count ) . eql ( 2 ) ;
@@ -89,14 +91,23 @@ test("should throw if invalid param", async (t) => {
89
91
} ) ;
90
92
91
93
test ( "should throw error if count > 1" , async ( t ) => {
92
- const nestedDivs = getAllByTestId ( / n e s t e d / ) ;
94
+ const nestedDivs = screen . getAllByTestId ( / n e s t e d / ) ;
93
95
94
96
await t . expect ( nestedDivs . count ) . eql ( 2 ) ;
95
97
let didThrow = false ;
96
98
try {
97
- await t . expect ( within ( nestedDivs ) . getByText ( "blah" ) ) ;
99
+ await t . expect ( within ( nestedDivs ) . getByText ( "blah" ) . exists ) ;
98
100
} catch ( e ) {
99
101
didThrow = true ;
100
102
}
101
103
await t . expect ( didThrow ) . ok ( ) ;
102
104
} ) ;
105
+
106
+ test ( "works with findBy queries" , async ( t ) => {
107
+ const group = screen . findByRole ( "group" , { name : "My Group" } ) ;
108
+
109
+ await t
110
+ . click ( within ( group ) . findByRole ( "button" , { name : "Increase B" } ) )
111
+ . expect ( within ( group ) . findByText ( "1" ) . exists )
112
+ . ok ( ) ;
113
+ } ) ;
0 commit comments