Skip to content

Instantly share code, notes, and snippets.

@ashleywxwx
Created August 15, 2017 14:24
Show Gist options
  • Select an option

  • Save ashleywxwx/dc4eb76c58f8d27f2dd6d8f6e6317045 to your computer and use it in GitHub Desktop.

Select an option

Save ashleywxwx/dc4eb76c58f8d27f2dd6d8f6e6317045 to your computer and use it in GitHub Desktop.
Mocha Promise Hooks Example
const {expect} = require("chai");
let asyncValue = null;
function slowPromise() {
return new Promise((resolve, reject) => {
let wait = setTimeout(() => {
clearTimeout(wait);
console.log("Timeout complete");
resolve("Finished");
}, 1000)
});
}
before(function(done) {
slowPromise()
.then((result) => {
console.log("Before - Promise resolved with: ", result);
asyncValue = result;
done();
})
})
it('test spec', function() {
console.log("Running test with value: ", asyncValue);
expect(asyncValue).to.equal("Finished");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment