should-equal
Advanced tools
Comparing version 0.1.1 to 0.2.0
15
index.js
@@ -30,2 +30,3 @@ var getType = require('should-type'); | ||
EQUALITY: 'A is not equal to B', | ||
EQUALITY_PROTOTYPE: 'A and B have different prototypes', | ||
WRAPPED_VALUE: 'A wrapped value is not equal to B wrapped value', | ||
@@ -163,2 +164,16 @@ FUNCTION_SOURCES: 'function A is not equal to B by source code value (via .toString call)', | ||
var prototypesEquals = false, canComparePrototypes = false; | ||
if(Object.getPrototypeOf) { | ||
prototypesEquals = Object.getPrototypeOf(a) === Object.getPrototypeOf(b); | ||
canComparePrototypes = true; | ||
} else if(a.__proto__ && b.__proto__) { | ||
prototypesEquals = a.__proto__ === b.__proto__; | ||
canComparePrototypes = true; | ||
} | ||
if(canComparePrototypes && !prototypesEquals) { | ||
return makeResult(false, path, REASON.EQUALITY_PROTOTYPE, a, b); | ||
} | ||
stackA.pop(); | ||
@@ -165,0 +180,0 @@ stackB.pop(); |
{ | ||
"name": "should-equal", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Deep comparison of 2 instances for should.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
41
test.js
@@ -331,2 +331,43 @@ var assert = require('assert'); | ||
ne(re1, /a/); | ||
}; | ||
exports['Date with props'] = function() { | ||
var now = Date.now(); | ||
var d1 = new Date(now); | ||
var d2 = new Date(now); | ||
d1.a = 10; | ||
ne(d1, d2); | ||
}; | ||
exports['Check object prototypes'] = function() { | ||
var nbRoot = { | ||
toString: function() { return this.first + ' ' + this.last; } | ||
}; | ||
function nameBuilder(first, last) { | ||
this.first = first; | ||
this.last = last; | ||
return this; | ||
} | ||
nameBuilder.prototype = nbRoot; | ||
function nameBuilder2(first, last) { | ||
this.first = first; | ||
this.last = last; | ||
return this; | ||
} | ||
nameBuilder2.prototype = nbRoot; | ||
var nb1 = new nameBuilder('Ryan', 'Dahl'); | ||
var nb2 = new nameBuilder2('Ryan', 'Dahl'); | ||
eq(nb1, nb2); | ||
nameBuilder2.prototype = Object; | ||
nb2 = new nameBuilder2('Ryan', 'Dahl'); | ||
ne(nb1, nb2); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16365
499
6