Created
January 16, 2016 09:57
-
-
Save khanghoang/c6b7b15598527e230aad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let waitsInProgress = []; | |
let message = `Timeout, it seems we don have the response from the async function`; | |
let waitFor = (testFunc, done, timeLeft = 2000) => { | |
waitsInProgress.push(setTimeout(() => { | |
if (timeLeft <= 0) { | |
done(new Error(message)); | |
} else if (testFunc()) { | |
done(); | |
} else { | |
waitFor(testFunc, done, timeLeft - 10); | |
} | |
}, 10)); | |
}; | |
waitFor.clear = () => waitsInProgress.map(clearTimeout); //optionally call this in the beforeEach to ensure rogue tests are not still waiting | |
export default waitFor; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment