Skip to content

Commit 8100f03

Browse files
authored
chore: updated testcafe examples to reflect 3.3.0 (#272)
1 parent 854814d commit 8100f03

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

docs/testcafe-testing-library/intro.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,30 +137,38 @@ import { within } from '@testing-library/testcafe'
137137
fixture`within`
138138
.page`http://localhost:13370`
139139

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 => {
141149
const { getByText } = await within('#nested')
142150
await t.click(getByText('Button Text')).ok()
143151
})
144152

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');
154155

156+
await t
157+
.expect(
158+
within(nested).getByText('Button Text')
159+
.exists).ok()
155160
});
156161

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 => {
158163
const nestedDivs = getAllByTestId(/nested/);
159164
await t.expect(nestedDivs.count).eql(2);
160-
const nested = await within(nestedDivs.nth(0));
161165

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+
163170
});
171+
164172
```
165173
[config]: https://testing-library.com/docs/dom-testing-library/api-configuration
166174
[gh]: https://github.com/benmonro/testcafe-testing-library

0 commit comments

Comments
 (0)