Skip to content

Commit 962dd2a

Browse files
benmonroalexkrolick
authored andcommitted
added config section for testcafe (#268)
1 parent 4d24643 commit 962dd2a

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

docs/testcafe-testing-library/intro.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fixture`selectors`.beforeEach(addTestcafeTestingLibrary)
3232
```
3333

3434
### for v3.x+ (requires testcafe 1.4.0 or greater)
35-
`addTestcafeTestingLibrary` was removed in 3.x, instead you can now inject clientScripts as of testcafe 1.4.0. For now, the path has to be used, but this will hopefully be changed to a module soon (pending a change to testcafe to support `umd:main` in package.json.
35+
`addTestcafeTestingLibrary` was removed in 3.x, instead you can now [inject clientScripts][inject] as of testcafe 1.4.0. For now, the path has to be used, but this will hopefully be changed to a module soon (pending a change to testcafe to support `umd:main` in package.json.
3636

3737
```json
3838
"clientScripts": [
@@ -68,6 +68,59 @@ test('getByLabelText', async t => {
6868
})
6969
```
7070

71+
## Configure
72+
You can customize the testIdAttribute using the [configure function of dom-testing-librarty][config] in a few different ways:
73+
74+
### Once in a single page load:
75+
```javascript
76+
import { configureOnce, getByTestId } from '@testing-library/testcafe';
77+
78+
test('can be configured once in a single page load', async t => {
79+
await configureOnce({ testIdAttribute: 'data-other-test-id' });
80+
await t.click(getByTestId('other-id'));
81+
})
82+
```
83+
84+
### For every test & page load in a fixture:
85+
```javascript
86+
import { configure, getByTestId, getByText } from '@testing-library/testcafe';
87+
88+
fixture`configure`.clientScripts(configure({ testIdAttribute: 'data-automation-id' }))
89+
.page`http://localhost:13370`
90+
91+
92+
test('supports alternative testIdAttribute', async t => {
93+
await t
94+
.click(getByTestId('image-with-random-alt-tag'))
95+
})
96+
97+
test('still works after browser page load and reload', async t => {
98+
await t.click(getByText('Go to Page 2'));
99+
100+
await t.eval(() => location.reload(true));
101+
102+
await t.click(getByTestId('page2-thing'))
103+
.expect(getByText('second page').exists).ok()
104+
})
105+
106+
```
107+
108+
### Globally for all fixtures, tests and page loads by [injecting clientScripts][inject]
109+
>Note: the dom-testing-library umd must come before your configure script
110+
111+
.testcaferc.json
112+
```json
113+
"clientScripts": [
114+
"./node_modules/@testing-library/dom/dist/@testing-library/dom.umd.js"
115+
"./path/to/my-app-testcafe.config.js"
116+
]
117+
```
118+
119+
./path/to/my-app-testcafe.config.js
120+
```javascript
121+
window.TestingLibraryDom.configure({ testIdAttribute: 'data-automation-id' });
122+
```
123+
71124
## Containers
72125

73126
By default the selectors come pre-bound to `document.body`, so no need to
@@ -109,5 +162,6 @@ test('works with nested selector from "All" query with index', async t => {
109162
await t.expect(nested.getByText('Button Text').exists).ok();
110163
});
111164
```
112-
165+
[config]: https://testing-library.com/docs/dom-testing-library/api-configuration
113166
[gh]: https://github.com/benmonro/testcafe-testing-library
167+
[inject]:https://devexpress.github.io/testcafe/documentation/using-testcafe/common-concepts/inject-scripts-into-tested-pages.html#add-client-scripts-to-all-tests

0 commit comments

Comments
 (0)