Skip to content

Instantly share code, notes, and snippets.

@Krxtopher
Forked from tobius/omit-callback-unit-test.js
Last active December 26, 2015 15:18
Show Gist options
  • Save Krxtopher/7171382 to your computer and use it in GitHub Desktop.
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.
/*
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