File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
docs/testcafe-testing-library Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,32 @@ test('getByLabelText', async t => {
58
58
})
59
59
```
60
60
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
+ ```
63
88
64
89
[ gh ] : https://github.com/benmonro/testcafe-testing-library
You can’t perform that action at this time.
0 commit comments