@@ -137,30 +137,38 @@ import { within } from '@testing-library/testcafe'
137
137
fixture` within`
138
138
.page ` http://localhost:13370`
139
139
140
- test (' getByText within container' , async t => {
140
+ test (' works with getBy* selectors' , async t => {
141
+ await t
142
+ .expect (
143
+ within (getByTestId (' nested' ))
144
+ .getByText (' Button Text' ).exists
145
+ ).ok ();
146
+ });
147
+
148
+ test (' works with CSS selector strings' , async t => {
141
149
const { getByText } = await within (' #nested' )
142
150
await t .click (getByText (' Button Text' )).ok ()
143
151
})
144
152
145
- test (" queryByPlaceholder doesn't find anything" , async t => {
146
- const { queryByPlaceholderText } = await within (' #nested' )
147
-
148
- await t .expect (queryByPlaceholderText (' Placeholder Text' ).exists ).notOk ()
149
- })
150
-
151
- test (' works with nested selectors' , async t => {
152
- const nested = await within (getByTestId (' nested' ));
153
- await t .expect (nested .getByText (' Button Text' ).exists ).ok ()
153
+ test (' works on any testcafe selector' , async (t ) => {
154
+ const nested = Selector (' #nested' );
154
155
156
+ await t
157
+ .expect (
158
+ within (nested).getByText (' Button Text' )
159
+ .exists ).ok ()
155
160
});
156
161
157
- test (' works with nested selector from "All " query with index' , async t => {
162
+ test (' works with results from "byAll " query with index - regex ' , async t => {
158
163
const nestedDivs = getAllByTestId (/ nested/ );
159
164
await t .expect (nestedDivs .count ).eql (2 );
160
- const nested = await within (nestedDivs .nth (0 ));
161
165
162
- await t .expect (nested .getByText (' Button Text' ).exists ).ok ();
166
+ await t
167
+ .expect (within (nestedDivs .nth (0 )).getByText (' Button Text' ).exists ).ok ()
168
+ .expect (within (nestedDivs .nth (1 )).getByText (' text only in 2nd nested' ).exists ).ok ()
169
+
163
170
});
171
+
164
172
```
165
173
[ config ] : https://testing-library.com/docs/dom-testing-library/api-configuration
166
174
[ gh ] : https://github.com/benmonro/testcafe-testing-library
0 commit comments