adding tests and fixing a bug where an error would be thrown when comparing an object and null

This commit is contained in:
Evan Seguin 2015-05-08 09:28:58 -07:00
parent effa9de53f
commit 5ae260820e
2 changed files with 13 additions and 1 deletions

View File

@ -11,9 +11,21 @@ describe('Utils', function() {
var objD = [{
foo: ['bar']
}];
var objE, objF;
var objG = null;
var objH = null;
expect(utils.isSame(objA, objB)).toBe(true);
expect(utils.isSame(objC, objD)).toBe(true);
expect(utils.isSame(objA, objD)).toBe(false);
expect(utils.isSame(objE, objF)).toBe(true);
expect(utils.isSame(objA, objF)).toBe(false);
expect(utils.isSame(objE, objA)).toBe(false);
expect(utils.isSame(objG, objH)).toBe(true);
expect(utils.isSame(objA, objH)).toBe(false);
expect(utils.isSame(objG, objA)).toBe(false);
});

View File

@ -31,7 +31,7 @@ module.exports = {
return false;
} else if (Array.isArray(a)) {
return !this.arraysDiffer(a, b);
} else if (typeof a === 'object' && a !== null) {
} else if (typeof a === 'object' && a !== null && b !== null) {
return !this.objectsDiffer(a, b);
}