File tree Expand file tree Collapse file tree 2 files changed +14
-13
lines changed Expand file tree Collapse file tree 2 files changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -31,25 +31,18 @@ Object.keys(queries).forEach(queryName => {
31
31
)
32
32
} )
33
33
34
- export const within = async sel => {
35
- const sanitizedSel = sel . replace ( / " / g, "'" )
36
- await ClientFunction (
37
- new Function (
38
- `
39
-
40
- window.TestcafeTestingLibrary = window.TestcafeTestingLibrary || {}
41
- const elem = document.querySelector("${ sanitizedSel } ");
42
- window.TestcafeTestingLibrary["within_${ sanitizedSel } "] = TestingLibraryDom.within(elem);
34
+ export const within = selector => {
35
+ const sanitizedSelector = selector . replace ( / " / g, "'" )
43
36
44
- ` ,
45
- ) ,
46
- ) ( )
47
37
const container = { }
48
38
49
39
Object . keys ( queries ) . forEach ( queryName => {
50
40
container [ queryName ] = Selector (
51
41
new Function (
52
- `return window.TestcafeTestingLibrary["within_${ sanitizedSel } "].${ queryName } (...arguments)` ,
42
+ `
43
+ window.TestcafeTestingLibrary = window.TestcafeTestingLibrary || {}
44
+ window.TestcafeTestingLibrary["within_${ sanitizedSelector } "] = window.TestcafeTestingLibrary["within_${ sanitizedSelector } "] || TestingLibraryDom.within(document.querySelector("${ sanitizedSelector } "))
45
+ return window.TestcafeTestingLibrary["within_${ sanitizedSelector } "].${ queryName } (...arguments)` ,
53
46
) ,
54
47
)
55
48
} )
Original file line number Diff line number Diff line change @@ -26,4 +26,12 @@ test('quotes in selector', async t => {
26
26
. click ( getByText ( 'Button Text' ) )
27
27
. expect ( Selector ( 'button' ) . withExactText ( 'Button Clicked' ) . exists )
28
28
. ok ( )
29
+ } ) ;
30
+
31
+ test ( 'still works after browser page reload' , async t => {
32
+ const nested = await within ( '#nested' ) ;
33
+ await t . expect ( nested . getByText ( 'Button Text' ) . exists ) . ok ( )
34
+
35
+ await t . eval ( ( ) => location . reload ( true ) ) ;
36
+ await t . expect ( nested . getByText ( 'Button Text' ) . exists ) . ok ( )
29
37
} )
You can’t perform that action at this time.
0 commit comments