fix tests

This commit is contained in:
Sharon Kennedy
2020-03-27 18:21:13 -04:00
parent 3fd9c7365d
commit 3f2aa3a9db
8 changed files with 65 additions and 9 deletions

30
src/utils/test-helpers.js Normal file
View File

@@ -0,0 +1,30 @@
function checkFunc(dom, selector) {
if (typeof dom.update === 'function') {
const el = dom.update().find(selector);
if (el.exists()) {
return el;
}
return null;
}
const els = dom.querySelectorAll(selector);
if (els.length !== 0) {
return els;
}
return null;
}
export async function waitForSelection(dom, selector) {
let numSleep = 0;
for (;;) {
const el = checkFunc(dom, selector);
if (el) {
return el;
}
if (numSleep > 2) {
throw new Error(`could not find ${selector}`);
}
await new Promise(resolve => setTimeout(resolve, 250));
numSleep += 1;
}
}