Skip to content

Instantly share code, notes, and snippets.

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 JoshuaKGoldberg/dad22ed2a315817ef903a4a6e0607f27 to your computer and use it in GitHub Desktop.
Save JoshuaKGoldberg/dad22ed2a315817ef903a4a6e0607f27 to your computer and use it in GitHub Desktop.
Demonstrates how chai-as-promised will correctly handle uncaught errors
// 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