-
-
Save Krxtopher/7171382 to your computer and use it in GitHub Desktop.
Here's my simplified version of Toby's original solution. This solution takes advantage of Jasmine's built-in toThrow() matcher which is similar to matchers in the should.js, expect.js, and chai assertion libraries which all work with Mocha.
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
/* | |
The implementation below assumes you're using Jasmine's built-in matchers. But similar matchers | |
exist in the should.js, expect.js, and chai assertion libraries which work with Mocha. | |
*/ | |
var makeSomething = function(callback) { | |
// Below is the simplest implementation that will result in the test passing. | |
// If you want a more robust implementation, you'll want to write more tests first. :) | |
throw(new Error("Missing parameters")); | |
}; | |
describe("makeSomething()", function() { | |
describe("when called with no callback parameter", function() { | |
it("should throw a meaningful error", function() { | |
expect(function() { | |
makeSomething(); | |
}).toThrow(new Error("Missing parameters")); | |
// Note, you can also use toThrow() with no params if you don't care about matching | |
// the exact error message. | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment