From a84eaf2cbe7a668d786236e008361932b4c1ce54 Mon Sep 17 00:00:00 2001 From: Rohit Arondekar Date: Sat, 20 Dec 2014 08:35:27 +0530 Subject: [PATCH] Allow null prototype obj to be compared for equals Fixes #729 --- spec/core/matchers/matchersUtilSpec.js | 20 ++++++++++++++++++++ src/core/matchers/matchersUtil.js | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index 443eef04..6f25dff1 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -250,6 +250,26 @@ describe("matchersUtil", function() { expect(j$.matchersUtil.equals(any1, any2)).toBe(true); }); + + it("passes for null prototype objects with same properties", function () { + var objA = Object.create(null), + objB = Object.create(null); + + objA.name = 'test'; + objB.name = 'test'; + + expect(j$.matchersUtil.equals(objA, objB)).toBe(true); + }); + + it("fails for null prototype objects with different properties", function () { + var objA = Object.create(null), + objB = Object.create(null); + + objA.name = 'test'; + objB.test = 'name'; + + expect(j$.matchersUtil.equals(objA, objB)).toBe(false); + }); }); describe("contains", function() { diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index f3f84632..49ec1145 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -197,7 +197,7 @@ getJasmineRequireObj().matchersUtil = function(j$) { return result; function has(obj, key) { - return obj.hasOwnProperty(key); + return Object.prototype.hasOwnProperty.call(obj, key); } function isFunction(obj) {