Skip to content

Commit

Permalink
Fail when passing undefined as the expectation for equals
Browse files Browse the repository at this point in the history
  • Loading branch information
mantoni committed Mar 9, 2019
1 parent 574839a commit 41f8748
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/assertions/equals.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ module.exports = function(referee) {
// Uses arguments[2] because the function's .length is used to determine
// the minimum required number of arguments.
assert: function(actual, expected) {
if (typeof expected === "undefined") {
return this.fail(
"Expectation for equals should not be undefined. Use assert.defined or refute.defined instead."
);
}
return samsam.deepEqual(actual, expected);
},
assertMessage:
Expand Down
4 changes: 2 additions & 2 deletions lib/assertions/equals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ testHelper.assertionTests("assert", "equals", function(pass, fail, msg, error) {
pass("when comparing numbers", 32, 32);
pass("when comparing booleans", false, false);
pass("when comparing null", null, null);
pass("when comparing undefined", undefined, undefined);
fail("when comparing undefined", undefined, undefined);
pass("when comparing function to itself", func, func);
fail("when comparing functions", function() {}, function() {});
pass("when comparing array to itself", arr, arr);
Expand Down Expand Up @@ -295,7 +295,7 @@ testHelper.assertionTests("refute", "equals", function(pass, fail, msg, error) {
pass("when comparing different objects", obj, {});
pass("when comparing object to null", {}, null);
pass("when comparing null to object", {}, null);
pass("when comparing object to undefined", {}, undefined);
fail("when comparing object to undefined", {}, undefined);
pass("when comparing undefined to object", undefined, {});
pass("when comparing object to false", {}, false);
pass("when comparing false to object", false, {});
Expand Down

0 comments on commit 41f8748

Please sign in to comment.