Skip to content

Commit

Permalink
add test for issue #14
Browse files Browse the repository at this point in the history
  • Loading branch information
warpech committed Oct 11, 2013
1 parent 710dd11 commit c7e48d4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/test-duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,35 @@ describe("JSON-Patch-Duplex", function () {
expect(patches).toEqual([]);
});

//related issue: https://github.com/Starcounter-Jack/JSON-Patch/issues/14
it('should generate the same patch using Object.observe and shim', function() {
var arr1 = [
["Albert", "Einstein"],
["Erwin", "Shrodinger"]
];

var arr2 = arr1.slice();

var newRecord = ['Niels', 'Bohr'];

var observer1 = jsonpatch.observe(arr1);
arr1.push(newRecord);

var objectObservePatches = jsonpatch.generate(observer1);

var _observe = Object.observe;
Object.observe = undefined;

var observer2 = jsonpatch.observe(arr2);
arr2.push(newRecord);

var shimPatches = jsonpatch.generate(observer2);

expect(objectObservePatches).toEqual(shimPatches);

Object.observe = _observe;
});

/*it('should not generate the same patch twice (move)', function() { //"move" is not implemented yet in jsonpatch.generate
obj = { lastName: {str: "Einstein"} };
var observer = jsonpatch.observe(obj);
Expand Down

0 comments on commit c7e48d4

Please sign in to comment.