forked from cdinger/jquery-objectdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjectdiff_spec.js
More file actions
38 lines (33 loc) · 1.39 KB
/
Copy pathobjectdiff_spec.js
File metadata and controls
38 lines (33 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
describe("objectDiff", function() {
it("should detect new properties in a simple, shallow object", function() {
var before = {id:123, name:"blah"};
var after = {id:123, name:"blah", age:30};
var diff = {age:[undefined,30]};
expect($.objectDiff(before, after)).toEqual(diff);
});
it("should detect deleted properties in a simple, shallow object", function() {
var before = {id:123, name:"blah", age:30};
var after = {id:123, name:"blah"};
var diff = {age:[30, undefined]};
expect($.objectDiff(before, after)).toEqual(diff);
});
it("should detect a change in a property value in a simple, shallow object", function() {
var before = {id:123, name:"blah"};
var after = {id:123, name:"asdf"};
var diff = {name:["blah","asdf"]};
expect($.objectDiff(before, after)).toEqual(diff);
});
it("should detect a change in a property value in a one-level nested object", function() {
var before = {id:123, name: {first:"Johnny", last:"Johnson"}};
var after = {id:123, name: {first:"John", last:"Johnson"}};
var diff = {name:{first:["Johnny","John"]}};
expect($.objectDiff(before, after)).toEqual(diff);
});
// Github issue #1
it("should not detect a change if before and after value is null", function() {
var before = {id:null};
var after = {id:null};
var diff = {};
expect($.objectDiff(before, after)).toEqual(diff);
});
});