Allow arrays from different frames or contexts to be equal
This commit is contained in:
@@ -171,6 +171,33 @@ describe("matchersUtil", function() {
|
|||||||
expect(j$.matchersUtil.equals(a,b)).toBe(true);
|
expect(j$.matchersUtil.equals(a,b)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("passes for equivalent objects from different vm contexts", function() {
|
||||||
|
if (typeof require !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var vm = require('vm');
|
||||||
|
var sandbox = {
|
||||||
|
obj: null
|
||||||
|
};
|
||||||
|
vm.runInNewContext('obj = {a: 1, b: 2}', sandbox);
|
||||||
|
|
||||||
|
expect(j$.matchersUtil.equals(sandbox.obj, {a: 1, b: 2})).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("passes for equivalent arrays from different vm contexts", function() {
|
||||||
|
if (typeof require !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var vm = require('vm');
|
||||||
|
var sandbox = {
|
||||||
|
arr: null
|
||||||
|
};
|
||||||
|
vm.runInNewContext('arr = [1, 2]', sandbox);
|
||||||
|
|
||||||
|
expect(j$.matchersUtil.equals(sandbox.arr, [1, 2])).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it("passes when Any is used", function() {
|
it("passes when Any is used", function() {
|
||||||
var number = 3,
|
var number = 3,
|
||||||
anyNumber = new j$.Any(Number);
|
anyNumber = new j$.Any(Number);
|
||||||
|
|||||||
@@ -167,11 +167,14 @@ getJasmineRequireObj().matchersUtil = function(j$) {
|
|||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
// Objects with different constructors are not equivalent, but `Object`s
|
// Objects with different constructors are not equivalent, but `Object`s
|
||||||
// from different frames are.
|
// or `Array`s from different frames are.
|
||||||
var aCtor = a.constructor, bCtor = b.constructor;
|
var areArrays = className === '[object Array]';
|
||||||
if (aCtor !== bCtor && !(isFunction(aCtor) && (aCtor instanceof aCtor) &&
|
if (!areArrays) {
|
||||||
isFunction(bCtor) && (bCtor instanceof bCtor))) {
|
var aCtor = a.constructor, bCtor = b.constructor;
|
||||||
return false;
|
if (aCtor !== bCtor && !(isFunction(aCtor) && aCtor instanceof aCtor &&
|
||||||
|
isFunction(bCtor) && bCtor instanceof bCtor)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Deep compare objects.
|
// Deep compare objects.
|
||||||
for (var key in a) {
|
for (var key in a) {
|
||||||
|
|||||||
Reference in New Issue
Block a user