Created
March 27, 2017 14:58
-
-
Save zackify/65984cf7252f576ed1971a056cd8a397 to your computer and use it in GitHub Desktop.
Global test helpers
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
//Useful helpers for async await in tests | |
global.sleep = time => | |
new Promise(resolve => setTimeout(() => resolve(), time)); | |
global.waitFor = (value, equal) => | |
new Promise(resolve => | |
setInterval( | |
() => { | |
if (value === equal) resolve(value); | |
}, | |
100 | |
)); | |
async test () => { | |
asyncStuff() | |
await sleep(5000) | |
let fakeNumber | |
await waitFor(fakeNumber, 5) //waits until the variable equals 5! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment