Skip to content

Commit

Permalink
Removed tests which were enforcing the use of native Object.observe o…
Browse files Browse the repository at this point in the history
…r shim.
  • Loading branch information
psmolenski committed Oct 25, 2013
1 parent 9fa205f commit c7b889b
Showing 1 changed file with 4 additions and 146 deletions.
150 changes: 4 additions & 146 deletions src/test-duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,16 +554,14 @@ describe("JSON-Patch-Duplex", function () {
});
});

it("should handle callbacks that calls observe() and unobserve() internally (native Object.observe)", function () {
it("should handle callbacks that calls observe() and unobserve() internally", function () {

var obj = {
foo: 'bar'
};

var observer;

expect(Object.observe).toBeDefined();

var callback = jasmine.createSpy('callback');
callback.plan = function(){
jsonpatch.unobserve(obj, observer);
Expand Down Expand Up @@ -600,106 +598,20 @@ describe("JSON-Patch-Duplex", function () {

});

it("should handle callbacks that calls observe() and unobserve() internally (Object.observe shim)", function () {

var obj = {
foo: 'bar'
};

var observer;

//Disable native Object.observe to force the use of shim
var nativeObserve = Object.observe;
delete Object.observe;

expect(Object.observe).toBeUndefined();

var callback = jasmine.createSpy('callback');
callback.plan = function(){
jsonpatch.unobserve(obj, observer);

jsonpatch.observe(obj, callback);
};

observer = jsonpatch.observe(obj, callback);

expect(callback.calls.length).toEqual(0);

obj.foo = 'bazz';

waitsFor(function () {
return callback.calls.length > 0;
}, 'callback calls', 1000);

runs(function () {
expect(callback.calls.length).toEqual(1);

callback.reset();

obj.foo = 'bazinga';
});

waitsFor(function () {
return callback.calls.length > 0;
}, 'callback calls', 1000);

runs(function () {
expect(callback.calls.length).toEqual(1);

Object.observe = nativeObserve;
});


});


});



describe("Registering multiple observers with the same callback", function () {

it("should register only one observer (native Object.observe)", function () {

var obj = {
foo: 'bar'
};

var callback = jasmine.createSpy('callback');

expect(Object.observe).toBeDefined();

jsonpatch.observe(obj, callback);
jsonpatch.observe(obj, callback);

expect(callback.calls.length).toEqual(0);

obj.foo = 'bazz';

waitsFor(function () {
return callback.calls.length > 0;
}, 'callback call', 1000);

runs(function () {
expect(callback.calls.length).toEqual(1);
});

});

it("should register only one observer (Object.observe shim )", function () {
it("should register only one observer", function () {

var obj = {
foo: 'bar'
};

var callback = jasmine.createSpy('callback');

//Disable native Object.observe to force the use of shim
var nativeObserve = Object.observe;
delete Object.observe;

expect(Object.observe).toBeUndefined();

jsonpatch.observe(obj, callback);
jsonpatch.observe(obj, callback);

Expand All @@ -713,20 +625,17 @@ describe("JSON-Patch-Duplex", function () {

runs(function () {
expect(callback.calls.length).toEqual(1);
Object.observe = nativeObserve;
});

});

it("should return the same observer if callback has been already registered (native Object.observe)", function () {
it("should return the same observer if callback has been already registered)", function () {
var obj = {
foo: 'bar'
};

var callback = jasmine.createSpy('callback');

expect(Object.observe).toBeDefined();

var observer1 = jsonpatch.observe(obj, callback);
var observer2 = jsonpatch.observe(obj, callback);

Expand All @@ -735,61 +644,13 @@ describe("JSON-Patch-Duplex", function () {

});

it("should return the same observer if callback has been already registered (Object.observe shim)", function () {
it("should return a different observer if callback has been unregistered and registered again", function () {
var obj = {
foo: 'bar'
};

//Disable native Object.observe to force the use of shim
var nativeObserve = Object.observe;
delete Object.observe;

var callback = jasmine.createSpy('callback');

expect(Object.observe).toBeUndefined();

var observer1 = jsonpatch.observe(obj, callback);
var observer2 = jsonpatch.observe(obj, callback);

expect(observer1).toBe(observer2);

Object.observe = nativeObserve;

});

it("should return a different observer if callback has been unregistered and registered again (native Object.observe)", function () {
var obj = {
foo: 'bar'
};

var callback = jasmine.createSpy('callback');

expect(Object.observe).toBeDefined();

var observer1 = jsonpatch.observe(obj, callback);

jsonpatch.unobserve(obj, observer1);

var observer2 = jsonpatch.observe(obj, callback);

expect(observer1).not.toBe(observer2);


});

it("should return a different observer if callback has been unregistered and registered again (Object.observe shim)", function () {
var obj = {
foo: 'bar'
};

var callback = jasmine.createSpy('callback');

//Disable native Object.observe to force the use of shim
var nativeObserve = Object.observe;
delete Object.observe;

expect(Object.observe).toBeUndefined();

var observer1 = jsonpatch.observe(obj, callback);

jsonpatch.unobserve(obj, observer1);
Expand All @@ -798,9 +659,6 @@ describe("JSON-Patch-Duplex", function () {

expect(observer1).not.toBe(observer2);

Object.observe = nativeObserve;


});
});

Expand Down

0 comments on commit c7b889b

Please sign in to comment.