You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using [`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) is more efficient than polling the DOM at regular intervals with `wait`. This library sets up a [`'mutationobserver-shim'`](https://github.com/megawac/MutationObserver.js) on the global `window` object for cross-platform compatibility with older browsers and the [`jsdom`](https://github.com/jsdom/jsdom/issues/639) that is usually used in Node-based tests.
// if 👆 was the only code affecting the container and it was not run,
125
139
// waitForDomChange would throw an error
126
140
```
127
141
128
-
Thepromisewillresolvewitha [`mutationsList`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/MutationObserver) which you can use to determine what kind of a change (or changes) affected the container
Using [`MutationObserver`](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) is more efficient than polling the DOM at regular intervals with `wait`. This library sets up a [`'mutationobserver-shim'`](https://github.com/megawac/MutationObserver.js) on the global `window` object for cross-platform compatibility with older browsers and the [`jsdom`](https://github.com/jsdom/jsdom/issues/639) that is usually used in Node-based tests.
**Keyboard events**: There are three event types related to keyboard input - `keyPress`, `keyDown`, and `keyUp`. When firing these you need to reference an element in the DOM and the key you want to fire.
62
+
**Keyboard events**: There are three event types related to keyboard input -
63
+
`keyPress`, `keyDown`, and `keyUp`. When firing these you need to reference an
Copy file name to clipboardExpand all lines: docs/api-helpers.md
+23-17
Original file line number
Diff line number
Diff line change
@@ -5,28 +5,32 @@ title: Helpers
5
5
6
6
## Custom Queries
7
7
8
-
`dom-testing-library` exposes many of the helper functions that are used to implement the default queries. You can use the helpers to build custom queries. For example, the code below shows a way to override the default `testId` queries to use a different data-attribute. (Note: test files would import `test-utils.js` instead of using `dom-testing-library` directly).
8
+
`dom-testing-library` exposes many of the helper functions that are used to
9
+
implement the default queries. You can use the helpers to build custom queries.
10
+
For example, the code below shows a way to override the default `testId` queries
11
+
to use a different data-attribute. (Note: test files would import
12
+
`test-utils.js` instead of using `dom-testing-library` directly).
`Unable to find an element by: [data-test-id="${id}"]`,
29
-
container,
33
+
container
30
34
)
31
35
}
32
36
return els
@@ -93,16 +97,16 @@ These elements use the attribute `value` and display its value to the user.
93
97
94
98
## Debugging
95
99
96
-
When you use any `get` calls in your test cases, the current state of the`container`
97
-
(DOM) gets printed on the console. For example:
100
+
When you use any `get` calls in your test cases, the current state of the
101
+
`container`(DOM) gets printed on the console. For example:
98
102
99
103
```javascript
100
104
// <div>Hello world</div>
101
105
getByText(container, 'Goodbye world') // will fail by throwing error
102
106
```
103
107
104
-
The above test case will fail, however it prints the state of your DOM under test,
105
-
so you will get to see:
108
+
The above test case will fail, however it prints the state of your DOM under
109
+
test, so you will get to see:
106
110
107
111
```
108
112
Unable to find an element with the text: Goodbye world. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
@@ -114,18 +118,19 @@ Here is the state of your container:
114
118
</div>
115
119
```
116
120
117
-
Note: Since the DOM size can get really large, you can set the limit of DOM content
118
-
to be printed via environment variable `DEBUG_PRINT_LIMIT`. The default value is
119
-
`7000`. You will see `...` in the console, when the DOM content is stripped off,
120
-
because of the length you have set or due to default size limit. Here's how you
121
-
might increase this limit when running tests:
121
+
Note: Since the DOM size can get really large, you can set the limit of DOM
122
+
content to be printed via environment variable `DEBUG_PRINT_LIMIT`. The default
123
+
value is `7000`. You will see `...` in the console, when the DOM content is
124
+
stripped off, because of the length you have set or due to default size limit.
125
+
Here's how you might increase this limit when running tests:
122
126
123
127
```
124
128
DEBUG_PRINT_LIMIT=10000 npm test
125
129
```
126
130
127
-
This works on macOS/linux, you'll need to do something else for windows. If you'd
128
-
like a solution that works for both, see [`cross-env`](https://www.npmjs.com/package/cross-env)
131
+
This works on macOS/linux, you'll need to do something else for windows. If
0 commit comments