Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail when passing undefined as the expectation for equals #87

Merged
merged 1 commit into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -292,7 +292,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