-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update waitForElementToBeRemoved docs #500
Merged
afontcu
merged 1 commit into
testing-library:master
from
tjefferson08:pr/update-waitforelementtoberemoved-docs
Jun 20, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,8 @@ function waitFor<T>( | |
): Promise<T> | ||
``` | ||
|
||
When in need to wait for any period of time you can use `waitFor`, to wait for your | ||
expectations to pass. Here's a simple example: | ||
When in need to wait for any period of time you can use `waitFor`, to wait for | ||
your expectations to pass. Here's a simple example: | ||
|
||
```javascript | ||
// ... | ||
|
@@ -63,24 +63,24 @@ function waitForElementToBeRemoved<T>( | |
interval?: number | ||
mutationObserverOptions?: MutationObserverInit | ||
} | ||
): Promise<T> | ||
): Promise<void> | ||
``` | ||
|
||
To wait for the removal of element(s) from the DOM you can use | ||
`waitForElementToBeRemoved`. The `waitForElementToBeRemoved` function is a small | ||
wrapper around the `wait` utility. | ||
wrapper around the `waitFor` utility. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here! |
||
|
||
The first argument must be an element, array of elements, or a callback which returns | ||
an element or array of elements. | ||
The first argument must be an element, array of elements, or a callback which | ||
returns an element or array of elements. | ||
|
||
Here is an example where the promise resolves with `true` because the element is | ||
removed: | ||
Here is an example where the promise resolves because the element is removed: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here (that's it!) |
||
|
||
```javascript | ||
const el = document.querySelector('div.getOuttaHere') | ||
|
||
waitForElementToBeRemoved(document.querySelector('div.getOuttaHere')) | ||
.then(() => console.log('Element no longer in DOM')) | ||
waitForElementToBeRemoved(document.querySelector('div.getOuttaHere')).then(() => | ||
console.log('Element no longer in DOM') | ||
) | ||
|
||
el.setAttribute('data-neat', true) | ||
// other mutations are ignored... | ||
|
@@ -94,9 +94,15 @@ or an empty array: | |
|
||
```javascript | ||
waitForElementToBeRemoved(null).catch(err => console.log(err)) | ||
waitForElementToBeRemoved(queryByText(/not here/i)).catch(err => console.log(err)) | ||
waitForElementToBeRemoved(queryAllByText(/not here/i)).catch(err => console.log(err)) | ||
waitForElementToBeRemoved(() => getByText(/not here/i)).catch(err => console.log(err)) | ||
waitForElementToBeRemoved(queryByText(/not here/i)).catch(err => | ||
console.log(err) | ||
) | ||
waitForElementToBeRemoved(queryAllByText(/not here/i)).catch(err => | ||
console.log(err) | ||
) | ||
waitForElementToBeRemoved(() => getByText(/not here/i)).catch(err => | ||
console.log(err) | ||
) | ||
|
||
// Error: The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal. | ||
``` | ||
|
@@ -116,9 +122,14 @@ function wait<T>( | |
} | ||
): Promise<T> | ||
``` | ||
Previously, wait was a wrapper around wait-for-expect and used polling instead of a MutationObserver to look for changes. It is now an alias to waitFor and will be removed in a future release. | ||
|
||
Unlike wait, the callback parameter is mandatory in waitFor. Although you can migrate an existing `wait()` call to `waitFor( () => {} )`, it is considered bad practice to use an empty callback because it will make the tests more fragile. | ||
Previously, wait was a wrapper around wait-for-expect and used polling instead | ||
of a MutationObserver to look for changes. It is now an alias to waitFor and | ||
will be removed in a future release. | ||
|
||
Unlike wait, the callback parameter is mandatory in waitFor. Although you can | ||
migrate an existing `wait()` call to `waitFor( () => {} )`, it is considered bad | ||
practice to use an empty callback because it will make the tests more fragile. | ||
|
||
## `waitForDomChange` (DEPRECATED, use waitFor instead) | ||
|
||
|
@@ -158,9 +169,7 @@ container.setAttribute('data-cool', 'true') | |
waitForDomChange({ container }).then(mutationsList => { | ||
const mutation = mutationsList[0] | ||
console.log( | ||
`was cool: ${mutation.oldValue}\ncurrently cool: ${ | ||
mutation.target.dataset.cool | ||
}` | ||
`was cool: ${mutation.oldValue}\ncurrently cool: ${mutation.target.dataset.cool}` | ||
) | ||
}) | ||
container.setAttribute('data-cool', 'false') | ||
|
@@ -183,7 +192,6 @@ will detect additions and removals of child elements (including text nodes) in | |
the `container` and any of its descendants. It will also detect attribute | ||
changes. | ||
|
||
|
||
## `waitForElement` (DEPRECATED, use `find*` queries or `waitFor`) | ||
|
||
```typescript | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intended change here!