Last active
July 19, 2018 12:31
-
-
Save jimmy-collazos/9d75baa9581cd3b20a8ecbc389fa2d43 to your computer and use it in GitHub Desktop.
Helper function - sleep()
This file contains hidden or 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
/** | |
* Create Promise pending to resolve after N milliseconds | |
* Example async-await: | |
* const { sleep } = require('sleep') | |
* //... | |
* it ('Should resolve after 100 millisiconds', async function () { | |
* let Module = load(path) | |
* await sleep(100) | |
* expect (Module.status).to.be.equal('resolved') | |
* }) | |
* | |
* Expample promise: | |
* const { sleep } = require('sleep') | |
* //... | |
* it ('Should resolve after 100 millisiconds', function (done) { | |
* let Module = load(path) | |
* sleep(100) | |
* .then(() => expect (Module.status).to.be.equal('resolved')) | |
* .then(done) | |
* }) | |
*/ | |
exports.sleep = (time) => new Promise((ok) => setTimeout(ok, time)) |
This file contains hidden or 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
/** | |
* Create Promise pending to resolve after N milliseconds | |
* Example async-await: | |
* import { sleep } from 'sleep' | |
* //... | |
* it ('Should resolve after 100 millisiconds', async function () { | |
* let Module = load(path) | |
* await sleep(100) | |
* expect (Module.status).to.be.equal('resolved') | |
* }) | |
* | |
* | |
* Expample promise: | |
* import { sleep } from 'sleep' | |
* //... | |
* it ('Should resolve after 100 millisiconds', function (done) { | |
* let Module = load(path) | |
* sleep(100) | |
* .then(() => expect (Module.status).to.be.equal('resolved')) | |
* .then(done) | |
* }) | |
*/ | |
export const sleep = (time) => new Promise((ok) => setTimeout(ok, time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment