mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-05-14 04:24:36 +08:00
fix for angular.Object.equals to handle equals({},null)
This commit is contained in:
@@ -631,6 +631,7 @@ function copy(source, destination){
|
||||
*/
|
||||
function equals(o1, o2) {
|
||||
if (o1 == o2) return true;
|
||||
if (o1 === null || o2 === null) return false;
|
||||
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
|
||||
if (t1 == t2 && t1 == 'object') {
|
||||
if (o1 instanceof Array) {
|
||||
|
||||
@@ -89,6 +89,28 @@ describe('equals', function(){
|
||||
it('should ignore functions', function(){
|
||||
expect(equals({func: function() {}}, {bar: function() {}})).toEqual(true);
|
||||
});
|
||||
|
||||
it('should work well with nulls', function() {
|
||||
expect(equals(null, '123')).toBe(false);
|
||||
expect(equals('123', null)).toBe(false);
|
||||
|
||||
var obj = {foo:'bar'};
|
||||
expect(equals(null, obj)).toBe(false);
|
||||
expect(equals(obj, null)).toBe(false);
|
||||
|
||||
expect(equals(null, null)).toBe(true);
|
||||
});
|
||||
|
||||
it('should work well with undefined', function() {
|
||||
expect(equals(undefined, '123')).toBe(false);
|
||||
expect(equals('123', undefined)).toBe(false);
|
||||
|
||||
var obj = {foo:'bar'};
|
||||
expect(equals(undefined, obj)).toBe(false);
|
||||
expect(equals(obj, undefined)).toBe(false);
|
||||
|
||||
expect(equals(undefined, undefined)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseKeyValue', function() {
|
||||
|
||||
Reference in New Issue
Block a user