forked from testing-library/dom-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait-for-element.js
32 lines (28 loc) 路 971 Bytes
/
wait-for-element.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {waitFor} from './wait-for'
let hasWarned = false
// deprecated... TODO: remove this method. People should use a find* query or
// wait instead the reasoning is that this doesn't really do anything useful
// that you can't get from using find* or wait.
async function waitForElement(callback, options) {
if (!hasWarned) {
hasWarned = true
console.warn(
`\`waitForElement\` has been deprecated. Use a \`find*\` query (preferred: https://testing-library.com/docs/dom-testing-library/api-queries#findby) or use \`waitFor\` instead: https://testing-library.com/docs/dom-testing-library/api-async#waitfor`,
)
}
if (!callback) {
throw new Error('waitForElement requires a callback as the first parameter')
}
return waitFor(() => {
const result = callback()
if (!result) {
throw new Error('Timed out in waitForElement.')
}
return result
}, options)
}
export {waitForElement}
/*
eslint
require-await: "off"
*/