@ -30,7 +30,7 @@ describe('HTML Imports', ifEnvSupports(supportsImports, function() {
|
||||
});
|
||||
});
|
||||
|
||||
document.head.appendChild(link !);
|
||||
document.head.appendChild(link!);
|
||||
});
|
||||
|
||||
function supportsOnEvents() {
|
||||
@ -56,7 +56,7 @@ describe('HTML Imports', ifEnvSupports(supportsImports, function() {
|
||||
};
|
||||
});
|
||||
|
||||
document.head.appendChild(link !);
|
||||
document.head.appendChild(link!);
|
||||
});
|
||||
|
||||
it('should work with onload', function(done) {
|
||||
@ -73,7 +73,7 @@ describe('HTML Imports', ifEnvSupports(supportsImports, function() {
|
||||
};
|
||||
});
|
||||
|
||||
document.head.appendChild(link !);
|
||||
document.head.appendChild(link!);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -14,7 +14,9 @@ describe('MutationObserver', ifEnvSupports('MutationObserver', function() {
|
||||
let elt: HTMLDivElement;
|
||||
const testZone = Zone.current.fork({name: 'test'});
|
||||
|
||||
beforeEach(function() { elt = document.createElement('div'); });
|
||||
beforeEach(function() {
|
||||
elt = document.createElement('div');
|
||||
});
|
||||
|
||||
it('should run observers within the zone', function(done) {
|
||||
let ob;
|
||||
@ -35,12 +37,18 @@ describe('MutationObserver', ifEnvSupports('MutationObserver', function() {
|
||||
let ob: MutationObserver;
|
||||
let flag = false;
|
||||
const elt = document.createElement('div');
|
||||
const childZone =
|
||||
Zone.current.fork({name: 'test', onInvokeTask: function() { flag = true; }});
|
||||
const childZone = Zone.current.fork({
|
||||
name: 'test',
|
||||
onInvokeTask: function() {
|
||||
flag = true;
|
||||
}
|
||||
});
|
||||
|
||||
childZone.run(function() { ob = new MutationObserver(function() {}); });
|
||||
childZone.run(function() {
|
||||
ob = new MutationObserver(function() {});
|
||||
});
|
||||
|
||||
ob !.disconnect();
|
||||
ob!.disconnect();
|
||||
expect(flag).toBe(false);
|
||||
});
|
||||
}));
|
||||
@ -62,6 +70,6 @@ describe('WebKitMutationObserver', ifEnvSupports('WebKitMutationObserver', funct
|
||||
ob.observe(elt, {childList: true});
|
||||
});
|
||||
|
||||
elt !.innerHTML = '<p>hey</p>';
|
||||
elt!.innerHTML = '<p>hey</p>';
|
||||
});
|
||||
}));
|
||||
|
@ -22,7 +22,9 @@ if (!window['saucelabs']) {
|
||||
|
||||
beforeEach(function(done) {
|
||||
socket = new WebSocket(TEST_SERVER_URL);
|
||||
socket.addEventListener('open', function() { done(); });
|
||||
socket.addEventListener('open', function() {
|
||||
done();
|
||||
});
|
||||
socket.addEventListener('error', function() {
|
||||
fail(
|
||||
'Can\'t establish socket to ' + TEST_SERVER_URL +
|
||||
@ -32,7 +34,9 @@ if (!window['saucelabs']) {
|
||||
}, TIMEOUT);
|
||||
|
||||
afterEach(function(done) {
|
||||
socket.addEventListener('close', function() { done(); });
|
||||
socket.addEventListener('close', function() {
|
||||
done();
|
||||
});
|
||||
socket.close();
|
||||
}, TIMEOUT);
|
||||
|
||||
@ -116,7 +120,9 @@ if (!window['saucelabs']) {
|
||||
it('should handler removing onmessage', function(done) {
|
||||
let log = '';
|
||||
|
||||
socket.onmessage = function() { log += 'a'; };
|
||||
socket.onmessage = function() {
|
||||
log += 'a';
|
||||
};
|
||||
|
||||
socket.onmessage = null as any;
|
||||
|
||||
|
@ -13,7 +13,9 @@ const wtfMock = global.wtfMock;
|
||||
describe('XMLHttpRequest', function() {
|
||||
let testZone: Zone;
|
||||
|
||||
beforeEach(() => { testZone = Zone.current.fork({name: 'test'}); });
|
||||
beforeEach(() => {
|
||||
testZone = Zone.current.fork({name: 'test'});
|
||||
});
|
||||
|
||||
it('should intercept XHRs and treat them as MacroTasks', function(done) {
|
||||
let req: XMLHttpRequest;
|
||||
@ -30,7 +32,9 @@ describe('XMLHttpRequest', function() {
|
||||
testZoneWithWtf.run(() => {
|
||||
req = new XMLHttpRequest();
|
||||
const logs: string[] = [];
|
||||
req.onload = () => { logs.push('onload'); };
|
||||
req.onload = () => {
|
||||
logs.push('onload');
|
||||
};
|
||||
onStable = function() {
|
||||
expect(wtfMock.log[wtfMock.log.length - 2])
|
||||
.toEqual('> Zone:invokeTask:XMLHttpRequest.send("<root>::ProxyZone::WTF::TestZone")');
|
||||
@ -96,7 +100,7 @@ describe('XMLHttpRequest', function() {
|
||||
req.open('get', '/', true);
|
||||
});
|
||||
|
||||
req !.send();
|
||||
req!.send();
|
||||
});
|
||||
|
||||
it('should return null when access ontimeout first time without error', function() {
|
||||
@ -104,7 +108,9 @@ describe('XMLHttpRequest', function() {
|
||||
expect(req.ontimeout).toBe(null);
|
||||
});
|
||||
|
||||
const supportsOnProgress = function() { return 'onprogress' in (new XMLHttpRequest()); };
|
||||
const supportsOnProgress = function() {
|
||||
return 'onprogress' in (new XMLHttpRequest());
|
||||
};
|
||||
|
||||
(<any>supportsOnProgress).message = 'XMLHttpRequest.onprogress';
|
||||
|
||||
@ -122,7 +128,7 @@ describe('XMLHttpRequest', function() {
|
||||
req.open('get', '/', true);
|
||||
});
|
||||
|
||||
req !.send();
|
||||
req!.send();
|
||||
});
|
||||
|
||||
it('should allow canceling of an XMLHttpRequest', function(done) {
|
||||
@ -132,13 +138,14 @@ describe('XMLHttpRequest', function() {
|
||||
|
||||
const trackingTestZone = Zone.current.fork({
|
||||
name: 'tracking test zone',
|
||||
onHasTask: (delegate: ZoneDelegate, current: Zone, target: Zone,
|
||||
hasTaskState: HasTaskState) => {
|
||||
if (hasTaskState.change == 'macroTask') {
|
||||
pending = hasTaskState.macroTask;
|
||||
}
|
||||
delegate.hasTask(target, hasTaskState);
|
||||
}
|
||||
onHasTask:
|
||||
(delegate: ZoneDelegate, current: Zone, target: Zone,
|
||||
hasTaskState: HasTaskState) => {
|
||||
if (hasTaskState.change == 'macroTask') {
|
||||
pending = hasTaskState.macroTask;
|
||||
}
|
||||
delegate.hasTask(target, hasTaskState);
|
||||
}
|
||||
});
|
||||
|
||||
trackingTestZone.run(function() {
|
||||
@ -234,8 +241,12 @@ describe('XMLHttpRequest', function() {
|
||||
req.onload = function() {
|
||||
req.onload = null as any;
|
||||
req.open('get', '/', true);
|
||||
req.onload = function() { done(); };
|
||||
expect(() => { req.send(); }).not.toThrow();
|
||||
req.onload = function() {
|
||||
done();
|
||||
};
|
||||
expect(() => {
|
||||
req.send();
|
||||
}).not.toThrow();
|
||||
};
|
||||
});
|
||||
});
|
||||
@ -248,7 +259,9 @@ describe('XMLHttpRequest', function() {
|
||||
req.send();
|
||||
req.addEventListener('readystatechange', function(ev) {
|
||||
if (req.readyState >= 2) {
|
||||
expect(() => { req.abort(); }).not.toThrow();
|
||||
expect(() => {
|
||||
req.abort();
|
||||
}).not.toThrow();
|
||||
done();
|
||||
}
|
||||
});
|
||||
@ -374,7 +387,9 @@ describe('XMLHttpRequest', function() {
|
||||
}
|
||||
};
|
||||
expect(req.onreadystatechange).toBe(listener);
|
||||
req.onreadystatechange = function() { return listener.call(this); };
|
||||
req.onreadystatechange = function() {
|
||||
return listener.call(this);
|
||||
};
|
||||
req.send();
|
||||
});
|
||||
}));
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,22 +26,34 @@ describe('customElements', function() {
|
||||
};
|
||||
|
||||
class TestCustomElement extends HTMLElement {
|
||||
constructor() { super(); }
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
static get observedAttributes() { return ['attr1', 'attr2']; }
|
||||
static get observedAttributes() {
|
||||
return ['attr1', 'attr2'];
|
||||
}
|
||||
|
||||
connectedCallback() { return bridge.connectedCallback(); }
|
||||
connectedCallback() {
|
||||
return bridge.connectedCallback();
|
||||
}
|
||||
|
||||
disconnectedCallback() { return bridge.disconnectedCallback(); }
|
||||
disconnectedCallback() {
|
||||
return bridge.disconnectedCallback();
|
||||
}
|
||||
|
||||
attributeChangedCallback(attrName, oldVal, newVal) {
|
||||
return bridge.attributeChangedCallback(attrName, oldVal, newVal);
|
||||
}
|
||||
|
||||
adoptedCallback() { return bridge.adoptedCallback(); }
|
||||
adoptedCallback() {
|
||||
return bridge.adoptedCallback();
|
||||
}
|
||||
}
|
||||
|
||||
testZone.run(() => { customElements.define('x-test', TestCustomElement); });
|
||||
testZone.run(() => {
|
||||
customElements.define('x-test', TestCustomElement);
|
||||
});
|
||||
|
||||
let elt;
|
||||
|
||||
|
@ -16,7 +16,9 @@ describe('element', function() {
|
||||
document.body.appendChild(button);
|
||||
});
|
||||
|
||||
afterEach(function() { document.body.removeChild(button); });
|
||||
afterEach(function() {
|
||||
document.body.removeChild(button);
|
||||
});
|
||||
|
||||
// https://github.com/angular/zone.js/issues/190
|
||||
it('should work when addEventListener / removeEventListener are called in the global context',
|
||||
@ -49,7 +51,9 @@ describe('element', function() {
|
||||
const clickEvent = document.createEvent('Event');
|
||||
clickEvent.initEvent('click', true, true);
|
||||
|
||||
button.addEventListener('click', function(event) { expect(event).toBe(clickEvent as any); });
|
||||
button.addEventListener('click', function(event) {
|
||||
expect(event).toBe(clickEvent as any);
|
||||
});
|
||||
|
||||
button.dispatchEvent(clickEvent);
|
||||
});
|
||||
@ -122,7 +126,9 @@ describe('element', function() {
|
||||
|
||||
it('should respect removeEventListener when called with a function listener', function() {
|
||||
let log = '';
|
||||
const logFunction = function logFunction() { log += 'a'; };
|
||||
const logFunction = function logFunction() {
|
||||
log += 'a';
|
||||
};
|
||||
|
||||
button.addEventListener('click', logFunction);
|
||||
button.addEventListener('focus', logFunction);
|
||||
@ -180,7 +186,9 @@ describe('element', function() {
|
||||
const log: string[] = [];
|
||||
const clickEvent = document.createEvent('Event');
|
||||
|
||||
function listener() { log.push('listener'); }
|
||||
function listener() {
|
||||
log.push('listener');
|
||||
}
|
||||
|
||||
clickEvent.initEvent('click', true, true);
|
||||
|
||||
@ -201,9 +209,13 @@ describe('element', function() {
|
||||
const log: string[] = [];
|
||||
const clickEvent = document.createEvent('Event');
|
||||
|
||||
function capturingListener() { log.push('capturingListener'); }
|
||||
function capturingListener() {
|
||||
log.push('capturingListener');
|
||||
}
|
||||
|
||||
function bubblingListener() { log.push('bubblingListener'); }
|
||||
function bubblingListener() {
|
||||
log.push('bubblingListener');
|
||||
}
|
||||
|
||||
clickEvent.initEvent('click', true, true);
|
||||
|
||||
@ -219,7 +231,9 @@ describe('element', function() {
|
||||
const log: string[] = [];
|
||||
const clickEvent = document.createEvent('Event');
|
||||
|
||||
function listener() { log.push('listener'); }
|
||||
function listener() {
|
||||
log.push('listener');
|
||||
}
|
||||
|
||||
clickEvent.initEvent('click', true, true);
|
||||
|
||||
@ -250,7 +264,9 @@ describe('element', function() {
|
||||
ifEnvSupports(supportsOnClick, function() {
|
||||
it('should spawn new child zones', function() {
|
||||
let run = false;
|
||||
button.onclick = function() { run = true; };
|
||||
button.onclick = function() {
|
||||
run = true;
|
||||
};
|
||||
|
||||
button.click();
|
||||
expect(run).toBeTruthy();
|
||||
@ -260,8 +276,12 @@ describe('element', function() {
|
||||
|
||||
it('should only allow one onclick handler', function() {
|
||||
let log = '';
|
||||
button.onclick = function() { log += 'a'; };
|
||||
button.onclick = function() { log += 'b'; };
|
||||
button.onclick = function() {
|
||||
log += 'a';
|
||||
};
|
||||
button.onclick = function() {
|
||||
log += 'b';
|
||||
};
|
||||
|
||||
button.click();
|
||||
expect(log).toEqual('b');
|
||||
@ -270,7 +290,9 @@ describe('element', function() {
|
||||
|
||||
it('should handler removing onclick', function() {
|
||||
let log = '';
|
||||
button.onclick = function() { log += 'a'; };
|
||||
button.onclick = function() {
|
||||
log += 'a';
|
||||
};
|
||||
button.onclick = null as any;
|
||||
|
||||
button.click();
|
||||
@ -293,10 +315,14 @@ describe('element', function() {
|
||||
document.body.appendChild(checkbox);
|
||||
});
|
||||
|
||||
afterEach(function() { document.body.removeChild(checkbox); });
|
||||
afterEach(function() {
|
||||
document.body.removeChild(checkbox);
|
||||
});
|
||||
|
||||
it('should be possible to prevent default behavior by returning false', function() {
|
||||
checkbox.onclick = function() { return false; };
|
||||
checkbox.onclick = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
checkbox.click();
|
||||
expect(checkbox.checked).toBe(false);
|
||||
|
@ -30,7 +30,9 @@ describe(
|
||||
callbackNames.forEach(function(callbackName) {
|
||||
const fullCallbackName = callbackName + 'Callback';
|
||||
const proto = Object.create(HTMLElement.prototype);
|
||||
(proto as any)[fullCallbackName] = function(arg: any) { callbacks[callbackName](arg); };
|
||||
(proto as any)[fullCallbackName] = function(arg: any) {
|
||||
callbacks[callbackName](arg);
|
||||
};
|
||||
(<any>document).registerElement('x-' + callbackName.toLowerCase(), {prototype: proto});
|
||||
});
|
||||
});
|
||||
@ -106,9 +108,11 @@ describe(
|
||||
testZone.run(function() {
|
||||
const proto = Object.create(HTMLElement.prototype);
|
||||
|
||||
Object.defineProperties(
|
||||
proto,
|
||||
{createdCallback: <any>{writable: false, configurable: false, value: checkZone}});
|
||||
Object.defineProperties(proto, {
|
||||
createdCallback: <any> {
|
||||
writable: false, configurable: false, value: checkZone
|
||||
}
|
||||
});
|
||||
|
||||
(<any>document).registerElement('x-props-desc', {prototype: proto});
|
||||
|
||||
@ -124,8 +128,9 @@ describe(
|
||||
it('should not throw with frozen prototypes ', function() {
|
||||
testZone.run(function() {
|
||||
const proto = Object.create(HTMLElement.prototype, Object.freeze(<PropertyDescriptorMap>{
|
||||
createdCallback:
|
||||
<PropertyDescriptor>{value: () => {}, writable: true, configurable: true}
|
||||
createdCallback: <PropertyDescriptor> {
|
||||
value: () => {}, writable: true, configurable: true
|
||||
}
|
||||
}));
|
||||
|
||||
Object.defineProperty(
|
||||
@ -159,6 +164,8 @@ describe(
|
||||
|
||||
|
||||
it('should not throw if no options passed to registerElement', function() {
|
||||
expect(function() { (<any>document).registerElement('x-no-opts'); }).not.toThrow();
|
||||
expect(function() {
|
||||
(<any>document).registerElement('x-no-opts');
|
||||
}).not.toThrow();
|
||||
});
|
||||
}));
|
||||
|
@ -16,14 +16,20 @@ describe('requestAnimationFrame', function() {
|
||||
functions.forEach(function(fnName) {
|
||||
describe(fnName, ifEnvSupports(fnName, function() {
|
||||
const originalTimeout: number = (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL;
|
||||
beforeEach(() => { (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = 10000; });
|
||||
beforeEach(() => {
|
||||
(<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = 10000;
|
||||
});
|
||||
|
||||
afterEach(() => { (<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = originalTimeout; });
|
||||
afterEach(() => {
|
||||
(<any>jasmine).DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||
});
|
||||
const rAF = window[fnName];
|
||||
|
||||
it('should be tolerant of invalid arguments', function() {
|
||||
// rAF throws an error on invalid arguments, so expect that.
|
||||
expect(function() { rAF(null); }).toThrow();
|
||||
expect(function() {
|
||||
rAF(null);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should bind to same zone when called recursively', function(done) {
|
||||
|
@ -25,8 +25,11 @@ describe('shadydom', () => {
|
||||
const target = t.target;
|
||||
const zone = Zone.current.fork({name: 'zone'});
|
||||
const logs: string[] = [];
|
||||
zone.run(
|
||||
() => { target.addEventListener('click', () => { logs.push(Zone.current.name); }); });
|
||||
zone.run(() => {
|
||||
target.addEventListener('click', () => {
|
||||
logs.push(Zone.current.name);
|
||||
});
|
||||
});
|
||||
const event = document.createEvent('MouseEvent');
|
||||
event.initEvent('click', true, true);
|
||||
target.dispatchEvent(event);
|
||||
|
Reference in New Issue
Block a user