Correctly remove spies of window.onerror on IE
This commit is contained in:
@@ -287,6 +287,24 @@ describe("SpyRegistry", function() {
|
||||
|
||||
expect(jasmineUnderTest.isSpy(subject.spiedFunc)).toBe(false);
|
||||
});
|
||||
|
||||
it("restores window.onerror by overwriting, not deleting", function() {
|
||||
function FakeWindow() {
|
||||
}
|
||||
FakeWindow.prototype.onerror = function() {};
|
||||
|
||||
var spies = [],
|
||||
global = new FakeWindow(),
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
global: global
|
||||
});
|
||||
|
||||
spyRegistry.spyOn(global, 'onerror');
|
||||
spyRegistry.clearSpies();
|
||||
expect(global.onerror).toBe(FakeWindow.prototype.onerror);
|
||||
expect(global.hasOwnProperty('onerror')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('spying on properties', function() {
|
||||
|
||||
34
spec/html/SpyRegistryHtmlSpec.js
Normal file
34
spec/html/SpyRegistryHtmlSpec.js
Normal file
@@ -0,0 +1,34 @@
|
||||
describe('Spy Registry browser-specific behavior', function() {
|
||||
it('can spy on and unspy window.onerror', function() {
|
||||
requireWriteableOnerror();
|
||||
|
||||
var spies = [],
|
||||
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
||||
currentSpies: function() { return spies; },
|
||||
global: window
|
||||
}),
|
||||
originalHandler = window.onerror;
|
||||
|
||||
try {
|
||||
spyRegistry.spyOn(window, 'onerror');
|
||||
spyRegistry.clearSpies();
|
||||
expect(window.onerror).toBe(originalHandler);
|
||||
} finally {
|
||||
window.onerror = originalHandler;
|
||||
}
|
||||
});
|
||||
|
||||
function requireWriteableOnerror() {
|
||||
var descriptor;
|
||||
|
||||
try {
|
||||
descriptor = Object.getOwnPropertyDescriptor(window, 'onerror');
|
||||
} catch(e) {
|
||||
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
||||
}
|
||||
|
||||
if (descriptor && !(descriptor.writable || descriptor.set)) {
|
||||
pending('Browser declares window.onerror to be readonly');
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user