Skip to content

Commit 1727a49

Browse files
TolseeKent C. Dodds
authored and
Kent C. Dodds
committed
feat(waitForElementToBeRemoved): add the new utility function (testing-library#218)
* Add tests and snapshots * Implement waitForElementToBeRemoved method * Export waitForElementToBeRemoved * Add as contributor * Update README.md after rebase * Throw error is the element is not present in the first place * Add test for full coverage * User jest time faker * Add typings * Cleanup * Update snapshot * Get rid of iife * Cleanup from review * Check for empty array as well * Check for error, falsy and empty to check whether the element is removed * error not defined error fix * Change snapshot to inline snapshot * Update snapshot * Only observe mutations if synchronous test passes * only observer if synchronous test passes fix * Await for the respective promise to resolve in test * Snapshot test to normal toHaveBeenCalledWith assertions * Update comment * Remove comment * test: improve tests for wait-for-element-to-be-removed * test: fix everything * test: do not test unstable node versions
1 parent ca7db36 commit 1727a49

24 files changed

+186
-104
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,15 @@
498498
"code",
499499
"test"
500500
]
501+
},
502+
{
503+
"login": "Tolsee",
504+
"name": "Tulsi Sapkota",
505+
"avatar_url": "https://avatars0.githubusercontent.com/u/16590492?v=4",
506+
"profile": "https://github.com/Tolsee",
507+
"contributions": [
508+
"code"
509+
]
501510
}
502511
]
503512
}

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ cache:
66
notifications:
77
email: false
88
node_js:
9-
- 'node'
109
- '10'
1110
- '8'
1211
install: npm install

CONTRIBUTING.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,6 @@ Thanks for being willing to contribute!
2727
> branch. Whenever you want to update your version of `master`, do a regular
2828
> `git pull`.
2929
30-
## Add yourself as a contributor
31-
32-
This project follows the [all contributors][all-contributors] specification.
33-
To add yourself to the table of contributors on the `README.md`, please use the
34-
automated script as part of your PR:
35-
36-
```console
37-
npm run add-contributor
38-
```
39-
40-
Follow the prompt and commit `.all-contributorsrc` and `README.md` in the PR.
41-
If you've already added yourself to the list and are making
42-
a new type of contribution, you can run it again and select the added
43-
contribution type.
44-
4530
## Committing and Pushing changes
4631
4732
Please make sure to run the tests before you commit your changes. You can run

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
[![downloads][downloads-badge]][npmtrends]
2121
[![MIT License][license-badge]][license]
2222

23-
[![All Contributors](https://img.shields.io/badge/all_contributors-50-orange.svg?style=flat-square)](#contributors)
23+
[![All Contributors](https://img.shields.io/badge/all_contributors-51-orange.svg?style=flat-square)](#contributors)
2424
[![PRs Welcome][prs-badge]][prs]
2525
[![Code of Conduct][coc-badge]][coc]
2626

@@ -138,7 +138,7 @@ Thanks goes to these people ([emoji key][emojis]):
138138
| [<img src="https://avatars3.githubusercontent.com/u/881986?v=4" width="100px;" alt="dadamssg"/><br /><sub><b>dadamssg</b></sub>](https://github.com/dadamssg)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=dadamssg "Code") | [<img src="https://avatars1.githubusercontent.com/u/186971?v=4" width="100px;" alt="Neil Kistner"/><br /><sub><b>Neil Kistner</b></sub>](https://neilkistner.com/)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=wyze "Code") | [<img src="https://avatars3.githubusercontent.com/u/1448597?v=4" width="100px;" alt="Ben Chauvette"/><br /><sub><b>Ben Chauvette</b></sub>](http://bdchauvette.net/)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=bdchauvette "Code") | [<img src="https://avatars2.githubusercontent.com/u/777527?v=4" width="100px;" alt="Jeff Baumgardt"/><br /><sub><b>Jeff Baumgardt</b></sub>](https://github.com/JeffBaumgardt)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=JeffBaumgardt "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=JeffBaumgardt "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/4658208?v=4" width="100px;" alt="Matan Kushner"/><br /><sub><b>Matan Kushner</b></sub>](http://matchai.me)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Documentation") [🤔](#ideas-matchai "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=matchai "Tests") | [<img src="https://avatars2.githubusercontent.com/u/5779538?v=4" width="100px;" alt="Alex Wendte"/><br /><sub><b>Alex Wendte</b></sub>](http://www.wendtedesigns.com/)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=themostcolm "Tests") | [<img src="https://avatars0.githubusercontent.com/u/2196208?v=4" width="100px;" alt="Tamas Fodor"/><br /><sub><b>Tamas Fodor</b></sub>](https://github.com/ruffle1986)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=ruffle1986 "Documentation") |
139139
| [<img src="https://avatars3.githubusercontent.com/u/14793495?v=4" width="100px;" alt="Benjamin Eckardt"/><br /><sub><b>Benjamin Eckardt</b></sub>](https://github.com/BenjaminEckardt)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=BenjaminEckardt "Code") | [<img src="https://avatars3.githubusercontent.com/u/205752?v=4" width="100px;" alt="Ryan Campbell"/><br /><sub><b>Ryan Campbell</b></sub>](https://github.com/campbellr)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=campbellr "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/1335519?v=4" width="100px;" alt="Taylor Briggs"/><br /><sub><b>Taylor Briggs</b></sub>](https://taylor-briggs.com)<br />[⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=TaylorBriggs "Tests") | [<img src="https://avatars2.githubusercontent.com/u/132233?v=4" width="100px;" alt="John Gozde"/><br /><sub><b>John Gozde</b></sub>](https://github.com/jgoz)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=jgoz "Code") | [<img src="https://avatars2.githubusercontent.com/u/3382565?v=4" width="100px;" alt="C. T. Lin"/><br /><sub><b>C. T. Lin</b></sub>](https://github.com/chentsulin)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=chentsulin "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/5312329?v=4" width="100px;" alt="Terrence Wong"/><br /><sub><b>Terrence Wong</b></sub>](http://terrencewwong.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=terrencewwong "Code") | [<img src="https://avatars0.githubusercontent.com/u/12230408?v=4" width="100px;" alt="Soo Jae Hwang"/><br /><sub><b>Soo Jae Hwang</b></sub>](https://www.ossfinder.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=misoguy "Code") |
140140
| [<img src="https://avatars0.githubusercontent.com/u/19773?v=4" width="100px;" alt="Royston Shufflebotham"/><br /><sub><b>Royston Shufflebotham</b></sub>](https://github.com/RoystonS)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3ARoystonS "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=RoystonS "Tests") | [<img src="https://avatars0.githubusercontent.com/u/591673?v=4" width="100px;" alt="Vadim Brodsky"/><br /><sub><b>Vadim Brodsky</b></sub>](http://www.vadimbrodsky.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=VadimBrodsky "Code") | [<img src="https://avatars3.githubusercontent.com/u/499898?v=4" width="100px;" alt="Eunjae Lee"/><br /><sub><b>Eunjae Lee</b></sub>](https://twitter.com/eunjae_lee)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=eunjae-lee "Code") | [<img src="https://avatars2.githubusercontent.com/u/167743?v=4" width="100px;" alt="David Peter"/><br /><sub><b>David Peter</b></sub>](http://davidpeter.me)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=sarenji "Code") | [<img src="https://avatars0.githubusercontent.com/u/13174025?v=4" width="100px;" alt="Shy Alter"/><br /><sub><b>Shy Alter</b></sub>](https://twitter.com/@puemos)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=puemos "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=puemos "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/11966621?v=4" width="100px;" alt="Łukasz Makuch"/><br /><sub><b>Łukasz Makuch</b></sub>](https://lukaszmakuch.pl)<br />[📦](#platform-lukaszmakuch "Packaging/porting to new platform") | [<img src="https://avatars1.githubusercontent.com/u/11150235?v=4" width="100px;" alt="Tyler Haas"/><br /><sub><b>Tyler Haas</b></sub>](https://github.com/tylerthehaas)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=tylerthehaas "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=tylerthehaas "Tests") |
141-
| [<img src="https://avatars2.githubusercontent.com/u/482561?v=4" width="100px;" alt="Vesa Laakso"/><br /><sub><b>Vesa Laakso</b></sub>](http://vesalaakso.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=valscion "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=valscion "Tests") |
141+
| [<img src="https://avatars2.githubusercontent.com/u/482561?v=4" width="100px;" alt="Vesa Laakso"/><br /><sub><b>Vesa Laakso</b></sub>](http://vesalaakso.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=valscion "Code") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=valscion "Tests") | [<img src="https://avatars0.githubusercontent.com/u/16590492?v=4" width="100px;" alt="Tulsi Sapkota"/><br /><sub><b>Tulsi Sapkota</b></sub>](https://github.com/Tolsee)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=Tolsee "Code") |
142142

143143
<!-- ALL-CONTRIBUTORS-LIST:END -->
144144

jest.config.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
const baseConfig = require('kcd-scripts/jest')
22

33
module.exports = {
4-
collectCoverageFrom: baseConfig.collectCoverageFrom,
5-
coverageThreshold: baseConfig.coverageThreshold,
6-
projects: [
7-
{
8-
...baseConfig,
9-
displayName: 'jsdom',
10-
testEnvironment: 'jest-environment-jsdom',
11-
},
12-
{
13-
...baseConfig,
14-
displayName: 'node',
15-
testEnvironment: 'jest-environment-node',
16-
},
17-
],
18-
// this is for eslint
19-
modulePaths: baseConfig.modulePaths,
4+
...baseConfig,
5+
testEnvironment: 'jest-environment-jsdom',
206
}

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,36 @@
2424
"node": ">=8"
2525
},
2626
"scripts": {
27-
"add-contributor": "kcd-scripts contributors add",
2827
"build": "kcd-scripts build && kcd-scripts build --bundle --no-clean",
2928
"lint": "kcd-scripts lint",
3029
"test": "kcd-scripts test",
3130
"test:update": "npm test -- --updateSnapshot --coverage",
3231
"validate": "kcd-scripts validate",
3332
"setup": "npm install && npm run validate -s",
34-
"precommit": "kcd-scripts precommit",
3533
"dtslint": "dtslint typings"
3634
},
35+
"husky": {
36+
"hooks": {
37+
"pre-commit": "kcd-scripts pre-commit"
38+
}
39+
},
3740
"files": [
3841
"dist",
3942
"typings"
4043
],
4144
"dependencies": {
42-
"@babel/runtime": "^7.1.5",
45+
"@babel/runtime": "^7.3.4",
4346
"@sheerun/mutationobserver-shim": "^0.3.2",
4447
"pretty-format": "^24.0.0",
4548
"wait-for-expect": "^1.1.0"
4649
},
4750
"devDependencies": {
48-
"dtslint": "^0.3.0",
49-
"jest-dom": "^2.1.1",
51+
"dtslint": "^0.5.3",
52+
"jest-dom": "^3.1.2",
5053
"jest-in-case": "^1.0.2",
51-
"jsdom": "^13.0.0",
52-
"kcd-scripts": "^0.46.0"
54+
"jest-watch-select-projects": "^0.1.1",
55+
"jsdom": "^13.2.0",
56+
"kcd-scripts": "^1.1.0"
5357
},
5458
"eslintConfig": {
5559
"extends": "./node_modules/kcd-scripts/eslint.js",

src/__tests__/element-queries.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'jest-dom/extend-expect'
22
import {configure} from '../config'
33
import {render, renderIntoDocument} from './helpers/test-utils'
4-
import document from './helpers/document'
54

65
beforeEach(() => {
76
document.defaultView.Cypress = null

src/__tests__/events.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import {fireEvent} from '..'
2-
import document from './helpers/document'
3-
import window from './helpers/window'
42

53
const eventTypes = [
64
{

src/__tests__/example.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import {getByLabelText, getByText, getByTestId, queryByTestId, wait} from '../'
33
// adds special assertions like toHaveTextContent
44
import 'jest-dom/extend-expect'
5-
import document from './helpers/document'
65

76
function getExampleDOM() {
87
// This is just a raw example of setting up some DOM

src/__tests__/get-queries-for-element.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {getQueriesForElement} from '../get-queries-for-element'
22
import {queries} from '..'
3-
import document from './helpers/document'
43

54
test('uses default queries', () => {
65
const container = document.createElement('div')

src/__tests__/helpers.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
import {getDocument, newMutationObserver} from '../helpers'
22

3-
describe('getDocument', () => {
4-
if (typeof document === 'undefined') {
5-
test('throws an error if window does not exist', () => {
6-
expect(() => getDocument()).toThrowError(
7-
/Could not find default container/,
8-
)
9-
})
10-
} else {
11-
test('returns global document if exists', () => {
12-
expect(getDocument()).toBe(document)
13-
})
14-
}
3+
test('returns global document if exists', () => {
4+
expect(getDocument()).toBe(document)
155
})
166

177
class DummyClass {

src/__tests__/helpers/document.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/__tests__/helpers/test-utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {getQueriesForElement} from '../../get-queries-for-element'
2-
import document from './document'
32

43
function render(html) {
54
const container = document.createElement('div')

src/__tests__/helpers/window.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/__tests__/pretty-dom.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {prettyDOM} from '../pretty-dom'
22
import {render} from './helpers/test-utils'
3-
import document from './helpers/document'
43

54
test('it prints out the given DOM element tree', () => {
65
const {container} = render('<div>Hello World!</div>')

src/__tests__/wait-for-dom-change.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {waitForDomChange} from '../'
22
// adds special assertions like toBeTruthy
33
import 'jest-dom/extend-expect'
44
import {render} from './helpers/test-utils'
5-
import document from './helpers/document'
65

76
const skipSomeTime = delayMs =>
87
new Promise(resolve => setTimeout(resolve, delayMs))
@@ -16,11 +15,7 @@ test('it waits for the next DOM mutation', async () => {
1615
const successHandler = jest.fn().mockName('successHandler')
1716
const errorHandler = jest.fn().mockName('errorHandler')
1817

19-
if (typeof window === 'undefined') {
20-
waitForDomChange({container: document}).then(successHandler, errorHandler)
21-
} else {
22-
waitForDomChange().then(successHandler, errorHandler)
23-
}
18+
waitForDomChange().then(successHandler, errorHandler)
2419

2520
// Promise callbacks are always asynchronous.
2621
expect(successHandler).toHaveBeenCalledTimes(0)
@@ -88,14 +83,7 @@ test('it throws if timeout is exceeded', async () => {
8883
const successHandler = jest.fn().mockName('successHandler')
8984
const errorHandler = jest.fn().mockName('errorHandler')
9085

91-
if (typeof window === 'undefined') {
92-
waitForDomChange({container: document, timeout: 70}).then(
93-
successHandler,
94-
errorHandler,
95-
)
96-
} else {
97-
waitForDomChange({timeout: 70}).then(successHandler, errorHandler)
98-
}
86+
waitForDomChange({timeout: 70}).then(successHandler, errorHandler)
9987

10088
await skipSomeTimeForMutationObserver(100)
10189

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'jest-dom/extend-expect'
2+
import {waitForElementToBeRemoved} from '../'
3+
import {render} from './helpers/test-utils'
4+
5+
jest.useFakeTimers()
6+
7+
test('requires a function as the first parameter', () => {
8+
return expect(
9+
waitForElementToBeRemoved(),
10+
).rejects.toThrowErrorMatchingInlineSnapshot(
11+
`"waitForElementToBeRemoved requires a function as the first parameter"`,
12+
)
13+
})
14+
15+
test('requires an element to exist first', () => {
16+
return expect(
17+
waitForElementToBeRemoved(() => null),
18+
).rejects.toThrowErrorMatchingInlineSnapshot(
19+
`"The callback function which was passed did not return an element or non-empty array of elements. waitForElementToBeRemoved requires that the element(s) exist before waiting for removal."`,
20+
)
21+
})
22+
23+
test('requires an unempty array of elements to exist first', () => {
24+
return expect(
25+
waitForElementToBeRemoved(() => []),
26+
).rejects.toThrowErrorMatchingInlineSnapshot(
27+
`"The callback function which was passed did not return an element or non-empty array of elements. waitForElementToBeRemoved requires that the element(s) exist before waiting for removal."`,
28+
)
29+
})
30+
31+
test('times out after 4500ms by default', () => {
32+
const {container} = render(`<div></div>`)
33+
const promise = expect(
34+
waitForElementToBeRemoved(() => container),
35+
).rejects.toThrowErrorMatchingInlineSnapshot(
36+
`"Timed out in waitForElementToBeRemoved."`,
37+
)
38+
jest.advanceTimersByTime(4501)
39+
return promise
40+
})
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import 'jest-dom/extend-expect'
2+
import {waitForElementToBeRemoved} from '../'
3+
import {renderIntoDocument} from './helpers/test-utils'
4+
5+
test('resolves on mutation only when the element is removed', async () => {
6+
const {queryAllByTestId} = renderIntoDocument(`
7+
<div data-testid="div"></div>
8+
<div data-testid="div"></div>
9+
`)
10+
const divs = queryAllByTestId('div')
11+
// first mutation
12+
setTimeout(() => {
13+
divs.forEach(d => d.setAttribute('id', 'mutated'))
14+
})
15+
// removal
16+
setTimeout(() => {
17+
divs.forEach(div => div.parentElement.removeChild(div))
18+
}, 100)
19+
// the timeout is here for two reasons:
20+
// 1. It helps test the timeout config
21+
// 2. The element should be removed immediately
22+
// so if it doesn't in the first 100ms then we know something's wrong
23+
// so we'll fail early and not wait the full timeout
24+
await waitForElementToBeRemoved(() => queryAllByTestId('div'), {timeout: 200})
25+
})
26+
27+
test('resolves on mutation if callback throws an error', async () => {
28+
const {getByTestId} = renderIntoDocument(`
29+
<div data-testid="div"></div>
30+
`)
31+
const div = getByTestId('div')
32+
setTimeout(() => {
33+
div.parentElement.removeChild(div)
34+
})
35+
await waitForElementToBeRemoved(() => getByTestId('div'), {timeout: 100})
36+
})

src/__tests__/wait-for-element.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {waitForElement, wait} from '../'
22
// adds special assertions like toBeTruthy
33
import 'jest-dom/extend-expect'
44
import {render} from './helpers/test-utils'
5-
import document from './helpers/document'
65

76
const skipSomeTime = delayMs =>
87
new Promise(resolve => setTimeout(resolve, delayMs))

src/__tests__/wait.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,3 @@ test('it waits for the data to be loaded', async () => {
1010
await wait(() => expect(spy).toHaveBeenCalledTimes(1))
1111
expect(spy).toHaveBeenCalledWith()
1212
})
13-
14-
test('can just be used for a next tick thing', async () => {
15-
jest.useFakeTimers()
16-
const spy = jest.fn()
17-
Promise.resolve().then(spy)
18-
expect(spy).toHaveBeenCalledTimes(0) // promises are always async
19-
await wait() // wait for next tick
20-
jest.advanceTimersByTime(60)
21-
expect(spy).toHaveBeenCalledTimes(1)
22-
jest.clearAllTimers()
23-
})

src/helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function newMutationObserver(onMutation) {
1111
}
1212

1313
function getDocument() {
14+
/* istanbul ignore if */
1415
if (typeof window === 'undefined') {
1516
throw new Error('Could not find default container')
1617
}

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as queryHelpers from './query-helpers'
55
export * from './queries'
66
export * from './wait'
77
export * from './wait-for-element'
8+
export * from './wait-for-element-to-be-removed'
89
export * from './wait-for-dom-change'
910
export {getDefaultNormalizer} from './matches'
1011
export * from './get-node-text'

0 commit comments

Comments
 (0)