mirror of
https://github.com/hanzoai/Detox.git
synced 2026-09-24 16:55:12 +00:00
23 lines
441 B
JavaScript
23 lines
441 B
JavaScript
const jestExpect = require('expect').default;
|
|
|
|
|
|
async function waitForCondition (func, condition, timeout = 5000) {
|
|
let isFulfilled = false;
|
|
|
|
const start = Date.now();
|
|
while (Date.now() - start < timeout) {
|
|
if (condition(await func())) {
|
|
isFulfilled = true;
|
|
break;
|
|
}
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
}
|
|
|
|
jestExpect(isFulfilled).toBe(true);
|
|
}
|
|
|
|
module.exports = {
|
|
waitForCondition
|
|
};
|