Created
January 18, 2017 22:48
-
-
Save JoshuaKGoldberg/dad22ed2a315817ef903a4a6e0607f27 to your computer and use it in GitHub Desktop.
Demonstrates how chai-as-promised will correctly handle uncaught errors
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
// Setup: npm install mocha chai chai-as-promised | |
// Run: node node_modules/mocha/bin/mocha | |
const chai = require("chai"); | |
const chaiAsPromised = require("chai-as-promised"); | |
const mocha = require("mocha"); | |
chai.use(chaiAsPromised); | |
const expect = chai.expect; | |
// Sample model test. | |
describe("Promises", function () { | |
it("should resolve using chai-as-promised", function () { | |
return expect(Promise.resolve("foo")).to.eventually.equal("foo"); | |
}); | |
it("this will throw", function () { | |
const promise = new Promise(() => { | |
setTimeout( | |
() => { | |
throw new Error("var self = this;"); | |
}, | |
1000); | |
}); | |
return expect(promise).to.eventually.be.fulfilled; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment