From 411ceb854174c5e8a2086bb4dbee079b7b37e981 Mon Sep 17 00:00:00 2001 From: Maximilian Antoni Date: Tue, 26 Feb 2019 21:15:03 +0100 Subject: [PATCH] Fail when passing undefined as the expectation for equals --- lib/assertions/equals.js | 5 +++++ lib/assertions/equals.test.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/assertions/equals.js b/lib/assertions/equals.js index 68ae56b2..eb416149 100644 --- a/lib/assertions/equals.js +++ b/lib/assertions/equals.js @@ -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: diff --git a/lib/assertions/equals.test.js b/lib/assertions/equals.test.js index 7260d643..04b35a81 100644 --- a/lib/assertions/equals.test.js +++ b/lib/assertions/equals.test.js @@ -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); @@ -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, {});