Skip to content

Commit e5338f6

Browse files
benmonroalexkrolick
authored andcommitted
added docs for within in testcafe-testing-library (#90)
* Create intro.md * doc: added testcafe-testing-library docs * doc: cleaned up some little details * added note for container * add docs for within
1 parent eb571e2 commit e5338f6

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

docs/testcafe-testing-library/intro.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,32 @@ test('getByLabelText', async t => {
5858
})
5959
```
6060

61-
**_Note:_** The selectors come pre-bound to `document.body`, so no need to
62-
provide a container.
61+
## Containers
62+
63+
By default the selectors come pre-bound to `document.body`, so no need to
64+
provide a container. However, if you want to restrict your query using a
65+
container, you can use `within`. Keep in mind that `within` works using a
66+
Testcafe `ClientFunction` so you will need to await it, and you can't make
67+
assertions on it like you can using a `Selector`.
68+
69+
### Examples using `within`
70+
71+
```javascript
72+
import { within, addTestcafeTestingLibrary } from 'testcafe-testing-library'
73+
74+
fixture`within`.beforeEach(addTestcafeTestingLibrary)
75+
.page`http://localhost:13370`
76+
77+
test('getByText within container', async t => {
78+
const { getByText } = await within('#nested')
79+
await t.click(getByText('Button Text')).ok()
80+
})
81+
82+
test("queryByPlaceholder doesn't find anything", async t => {
83+
const { queryByPlaceholderText } = await within('#nested')
84+
85+
await t.expect(queryByPlaceholderText('Placeholder Text').exists).notOk()
86+
})
87+
```
6388

6489
[gh]: https://github.com/benmonro/testcafe-testing-library

0 commit comments

Comments
 (0)