11import { Selector } from "testcafe" ;
2- import { within , getAllByTestId , getByTestId } from "../../src" ;
2+ import { within , screen } from "../../src" ;
33
44fixture `within` . page `../../test-app/index.html` ;
55
@@ -30,18 +30,20 @@ test("still works after browser page reload", async (t) => {
3030 const nested = await within ( "#nested" ) ;
3131 await t . expect ( nested . getByText ( "Button Text" ) . exists ) . ok ( ) ;
3232
33- await t . eval ( ( ) => location . reload ( true ) ) ;
33+ await t . eval ( ( ) => location . reload ( ) ) ;
3434 await t . expect ( nested . getByText ( "Button Text" ) . exists ) . ok ( ) ;
3535} ) ;
3636
3737test ( "works with nested selectors" , async ( t ) => {
3838 await t
39- . expect ( within ( getByTestId ( "nested" ) ) . getByText ( "Button Text" ) . exists )
39+ . expect (
40+ within ( screen . getByTestId ( "nested" ) ) . getByText ( "Button Text" ) . exists
41+ )
4042 . ok ( ) ;
4143} ) ;
4244
4345test ( '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 / ) ;
4547 await t . expect ( nestedDivs . count ) . eql ( 2 ) ;
4648
4749 const nested = within ( nestedDivs . nth ( 1 ) ) ;
@@ -54,15 +56,15 @@ test('works with nested selector from "All" query with index - regex', async (t)
5456} ) ;
5557
5658test ( '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 } ) ;
5860 await t . expect ( nestedDivs . count ) . eql ( 2 ) ;
5961 const nested = await within ( nestedDivs . nth ( 0 ) ) ;
6062
6163 await t . expect ( nested . getByText ( "Button Text" ) . exists ) . ok ( ) ;
6264} ) ;
6365
6466test ( '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 ) =>
6668 element . getAttribute ( "data-testid" ) ! . startsWith ( "nested" )
6769 ) ;
6870 await t . expect ( nestedDivs . count ) . eql ( 2 ) ;
@@ -89,14 +91,23 @@ test("should throw if invalid param", async (t) => {
8991} ) ;
9092
9193test ( "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 / ) ;
9395
9496 await t . expect ( nestedDivs . count ) . eql ( 2 ) ;
9597 let didThrow = false ;
9698 try {
97- await t . expect ( within ( nestedDivs ) . getByText ( "blah" ) ) ;
99+ await t . expect ( within ( nestedDivs ) . getByText ( "blah" ) . exists ) ;
98100 } catch ( e ) {
99101 didThrow = true ;
100102 }
101103 await t . expect ( didThrow ) . ok ( ) ;
102104} ) ;
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