Skip to content

Commit 62b98d8

Browse files
committed
wait-for-element-to-be-removed
1 parent f8becd7 commit 62b98d8

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {waitFor} from './wait-for'
1+
import {waitFor, WaitForOptions} from './wait-for'
22

33
const isRemoved = result => !result || (Array.isArray(result) && !result.length)
44

@@ -12,26 +12,32 @@ function initialCheck(elements) {
1212
}
1313
}
1414

15-
async function waitForElementToBeRemoved(callback, options) {
15+
async function waitForElementToBeRemoved<T extends Node>(
16+
callback: (() => T | T[]) | T | T[],
17+
options?: WaitForOptions,
18+
) {
1619
// created here so we get a nice stacktrace
1720
const timeoutError = new Error('Timed out in waitForElementToBeRemoved.')
21+
let cb
1822
if (typeof callback !== 'function') {
1923
initialCheck(callback)
20-
const elements = Array.isArray(callback) ? callback : [callback]
24+
const elements: Array<T> = Array.isArray(callback) ? callback : [callback]
2125
const getRemainingElements = elements.map(element => {
2226
let parent = element.parentElement
2327
while (parent.parentElement) parent = parent.parentElement
2428
return () => (parent.contains(element) ? element : null)
2529
})
26-
callback = () => getRemainingElements.map(c => c()).filter(Boolean)
30+
cb = () => getRemainingElements.map(c => c()).filter(Boolean)
31+
} else {
32+
cb = callback
2733
}
2834

29-
initialCheck(callback())
35+
initialCheck(cb())
3036

3137
return waitFor(() => {
3238
let result
3339
try {
34-
result = callback()
40+
result = cb()
3541
} catch (error) {
3642
if (error.name === 'TestingLibraryElementError') {
3743
return true
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {WaitForOptions} from './wait-for'
2-
3-
export function waitForElementToBeRemoved<T>(
4-
callback: (() => T) | T,
2+
declare function waitForElementToBeRemoved<T extends Node>(
3+
callback: (() => T | T[]) | T | T[],
54
options?: WaitForOptions,
6-
): Promise<T>
5+
): Promise<boolean>
6+
export {waitForElementToBeRemoved}

0 commit comments

Comments
 (0)