Forked from tobius/omit-callback-unit-test.js
Last active
December 26, 2015 15:18
Revisions
-
Krxtopher revised this gist
Oct 26, 2013 . 1 changed file with 11 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,25 +5,25 @@ exist in the should.js, expect.js, and chai assertion libraries which work with 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. }); }); }); -
Krxtopher revised this gist
Oct 26, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ exist in the should.js, expect.js, and chai assertion libraries which work with */ 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")); }; -
Krxtopher revised this gist
Oct 26, 2013 . 1 changed file with 19 additions and 57 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,67 +1,29 @@ /* 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. }); }); }); -
tobius created this gist
Oct 25, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ // node module var assert = require('better-assert'); /** * make something * * @param {Function} callback(err, something) */ var makeSomething = function(callback){ var something = 1; if (arguments.length >= 1){ something++; callback(err, something); } else { // nothing = fail // do not throw error = fail // do not throw custom error message = fail // throw custom error message = pass throw new Error('Missing parameters'); } }; describe('makeSomething()', function(){ it('should be a function', function(){ assert(makeSomething !== undefined, 'must not be undefined'); assert(typeof makeSomething === 'function', 'must be a function'); }); describe('making something to callback to nothing', function(){ it('should throw a meaningful error', function(done){ var err; try { makeSomething(); } catch(e){ err = e; assert(err !== undefined, 'must throw a catchable error'); assert(err.toString() !== 'Error', 'must throw a meaningful error'); } finally { assert(err !== undefined, 'must throw an error'); done(); } }); }); });