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
feat(waitForElement): a wrapper around MutationObserver (#10)
* feat(waitForElements): add implementation, tests, docs
Add `mutationobserver-shim` to `devDependencies` to provide
`MutationObserver` in jest tests where `jsdom` has no built-in support
for it: jsdom/jsdom#639
* docs(contributors): update sompylasar
* CR changes
- rename `waitForElements` to `waitForElement`
- move `mutationobserver-shim` to dependencies, import from
`waitForElement` to provide the polyfill to the users of
`dom-testing-library`
- fix `kcd-scripts` version to match `master` branch
- add synchronous `callback` call to detect an element if it's already
present before any DOM mutation happens
- add/change tests about synchronous `callback` call
- tweak variable names in docs examples
- add docs about the default `container` option value
- add docs example about querying multiple elements
- add docs about the `mutationobserver-shim` polyfill
- add docs link and anchor to `mutationObserverOptions`
- add docs link to MDN from the second mention of `MutationObserver`
* fix(waitForElement): ensure it works with default callback
Should wait for the next DOM change, as advertised in the docs.
The default value is `undefined` so that the `options` object can be
used while still keeping the default callback:
```
waitForElement(undefined, {attributes: true})
```
* CR: tweak docs examples for wait and waitForElement
- use `container` in the examples as this is a more popular use case
than the default value of global `document`
- use full sentences with capital first letter and period in the
example comments
* CR: rename files to kebab-case
* CR: await promise -> return promise
@kentcdodds:
> Rather than `await promise`, I'd prefer `return promise`. Maybe I'm
being irrational here, but it feels better to me.
@sompylasar:
> I'm changing this, but if this line was the only one with `await`
expression, then `eslint` would say `async` function must have an
`await`. We are lucky that there are more `await`s in all the tests.
>
> P.S. I don't agree with this rule because `async` functions have
their use for the error handling; `async` function is just the one that
is wrapped in a `return new Promise(...)`.
* CR: shorter timeouts and wait times for quicker tests
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.
0 commit comments