Skip to content

Commit 50c6353

Browse files
authored
Merge branch 'master' into fix/pass-container-to-wait-for
2 parents a40638c + 71b4f46 commit 50c6353

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

.all-contributorsrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,16 @@
13011301
"bug",
13021302
"code"
13031303
]
1304+
},
1305+
{
1306+
"login": "AriPerkkio",
1307+
"name": "Ari Perkkiö",
1308+
"avatar_url": "https://avatars2.githubusercontent.com/u/14806298?v=4",
1309+
"profile": "https://codepen.io/ariperkkio/",
1310+
"contributions": [
1311+
"bug",
1312+
"code"
1313+
]
13041314
}
13051315
],
13061316
"repoHost": "https://github.com"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ Thanks goes to these people ([emoji key][emojis]):
300300
<td align="center"><a href="https://github.com/romain-trotard"><img src="https://avatars0.githubusercontent.com/u/17161484?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Romain Trotard</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=romain-trotard" title="Code">💻</a></td>
301301
<td align="center"><a href="http://www.thomasmarshall.com"><img src="https://avatars0.githubusercontent.com/u/770763?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Thomas Marshall</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/commits?author=thomasmarshall" title="Code">💻</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=thomasmarshall" title="Tests">⚠️</a></td>
302302
<td align="center"><a href="https://github.com/johnjesse"><img src="https://avatars1.githubusercontent.com/u/6839660?v=4?s=100" width="100px;" alt=""/><br /><sub><b>johnjessewood</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/issues?q=author%3Ajohnjesse" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=johnjesse" title="Code">💻</a></td>
303+
<td align="center"><a href="https://codepen.io/ariperkkio/"><img src="https://avatars2.githubusercontent.com/u/14806298?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ari Perkkiö</b></sub></a><br /><a href="https://github.com/testing-library/dom-testing-library/issues?q=author%3AAriPerkkio" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/dom-testing-library/commits?author=AriPerkkio" title="Code">💻</a></td>
303304
</tr>
304305
</table>
305306

src/__tests__/wait-for-element-to-be-removed.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ test('requires an element to exist first', () => {
4242
)
4343
})
4444

45+
test("requires element's parent to exist first", () => {
46+
const {getByTestId} = renderIntoDocument(`
47+
<div data-testid="div">asd</div>
48+
`)
49+
const div = getByTestId('div')
50+
div.parentElement.removeChild(div)
51+
52+
return expect(
53+
waitForElementToBeRemoved(div),
54+
).rejects.toThrowErrorMatchingInlineSnapshot(
55+
`"The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal."`,
56+
)
57+
})
58+
4559
test('requires an unempty array of elements to exist first', () => {
4660
return expect(
4761
waitForElementToBeRemoved([]),

src/wait-for-element-to-be-removed.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async function waitForElementToBeRemoved(callback, options) {
2020
const elements = Array.isArray(callback) ? callback : [callback]
2121
const getRemainingElements = elements.map(element => {
2222
let parent = element.parentElement
23+
if(parent === null) return () => null
2324
while (parent.parentElement) parent = parent.parentElement
2425
return () => (parent.contains(element) ? element : null)
2526
})

0 commit comments

Comments
 (0)