Skip to content

Commit

Permalink
Merge branch 'juliemr-arrayfix'
Browse files Browse the repository at this point in the history
Fixes #765
  • Loading branch information
Greg Cobb and Gregg Van Hove committed Feb 4, 2015
2 parents e173cd1 + 53b0752 commit f22862f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
14 changes: 8 additions & 6 deletions lib/jasmine-core/jasmine.js
Expand Up @@ -2461,11 +2461,13 @@ getJasmineRequireObj().matchersUtil = function(j$) {

if (result) {
// Objects with different constructors are not equivalent, but `Object`s
// from different frames are.
var aCtor = a.constructor, bCtor = b.constructor;
if (aCtor !== bCtor && !(isFunction(aCtor) && (aCtor instanceof aCtor) &&
isFunction(bCtor) && (bCtor instanceof bCtor))) {
return false;
// or `Array`s from different frames are.
if (className !== '[object Array]') {
var aCtor = a.constructor, bCtor = b.constructor;
if (aCtor !== bCtor && !(isFunction(aCtor) && aCtor instanceof aCtor &&
isFunction(bCtor) && bCtor instanceof bCtor)) {
return false;
}
}
// Deep compare objects.
for (var key in a) {
Expand Down Expand Up @@ -3044,5 +3046,5 @@ getJasmineRequireObj().interface = function(jasmine, env) {
};

getJasmineRequireObj().version = function() {
return '2.2.0';
return '2.2.1';
};
27 changes: 27 additions & 0 deletions spec/core/matchers/matchersUtilSpec.js
Expand Up @@ -171,6 +171,33 @@ describe("matchersUtil", function() {
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() {
var number = 3,
anyNumber = new j$.Any(Number);
Expand Down
12 changes: 7 additions & 5 deletions src/core/matchers/matchersUtil.js
Expand Up @@ -167,11 +167,13 @@ getJasmineRequireObj().matchersUtil = function(j$) {

if (result) {
// Objects with different constructors are not equivalent, but `Object`s
// from different frames are.
var aCtor = a.constructor, bCtor = b.constructor;
if (aCtor !== bCtor && !(isFunction(aCtor) && (aCtor instanceof aCtor) &&
isFunction(bCtor) && (bCtor instanceof bCtor))) {
return false;
// or `Array`s from different frames are.
if (className !== '[object Array]') {
var aCtor = a.constructor, bCtor = b.constructor;
if (aCtor !== bCtor && !(isFunction(aCtor) && aCtor instanceof aCtor &&
isFunction(bCtor) && bCtor instanceof bCtor)) {
return false;
}
}
// Deep compare objects.
for (var key in a) {
Expand Down

0 comments on commit f22862f

Please sign in to comment.