Skip to content

Instantly share code, notes, and snippets.

@zackify
Created March 27, 2017 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackify/65984cf7252f576ed1971a056cd8a397 to your computer and use it in GitHub Desktop.
Save zackify/65984cf7252f576ed1971a056cd8a397 to your computer and use it in GitHub Desktop.
Global test helpers
//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