style(lint): re-format modules/@angular

This commit is contained in:
Alex Eagle
2016-06-08 16:38:52 -07:00
parent bbed364e7b
commit f39c9c9e75
589 changed files with 21829 additions and 24259 deletions

View File

@ -1,40 +1,16 @@
import {
beforeEach,
afterEach,
describe,
expect,
inject,
it,
AsyncTestCompleter
} from "@angular/core/testing/testing_internal";
import {Log} from "@angular/core/testing";
import {stringify} from "../../src/facade/lang";
import {
BROWSER_PLATFORM_PROVIDERS,
BROWSER_APP_PROVIDERS,
BROWSER_APP_COMPILER_PROVIDERS,
bootstrap
} from "@angular/platform-browser";
import {ApplicationRef, disposePlatform} from "@angular/core/src/application_ref";
import {Console} from "@angular/core/src/console";
import {
Component,
Directive,
OnDestroy,
provide,
Inject,
PLATFORM_INITIALIZER,
APP_INITIALIZER,
coreLoadAndBootstrap,
createPlatform,
ReflectiveInjector,
ExceptionHandler
} from "@angular/core";
import {getDOM} from "@angular/platform-browser/src/dom/dom_adapter";
import {DOCUMENT} from "@angular/platform-browser/src/dom/dom_tokens";
import {PromiseWrapper} from "../../src/facade/async";
import {Testability, TestabilityRegistry} from "@angular/core/src/testability/testability";
import {ComponentRef} from "@angular/core/src/linker/component_factory";
import {APP_INITIALIZER, Component, Directive, ExceptionHandler, Inject, OnDestroy, PLATFORM_INITIALIZER, ReflectiveInjector, coreLoadAndBootstrap, createPlatform, provide} from '@angular/core';
import {ApplicationRef, disposePlatform} from '@angular/core/src/application_ref';
import {Console} from '@angular/core/src/console';
import {ComponentRef} from '@angular/core/src/linker/component_factory';
import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
import {Log} from '@angular/core/testing';
import {AsyncTestCompleter, afterEach, beforeEach, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
import {BROWSER_APP_COMPILER_PROVIDERS, BROWSER_APP_PROVIDERS, BROWSER_PLATFORM_PROVIDERS, bootstrap} from '@angular/platform-browser';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';
import {PromiseWrapper} from '../../src/facade/async';
import {stringify} from '../../src/facade/lang';
@Component({selector: 'hello-app', template: '{{greeting}} world!'})
class HelloRootCmp {
@ -57,7 +33,9 @@ class HelloRootCmp2 {
class HelloRootCmp3 {
appBinding: any /** TODO #9100 */;
constructor(@Inject("appBinding") appBinding: any /** TODO #9100 */) { this.appBinding = appBinding; }
constructor(@Inject('appBinding') appBinding: any /** TODO #9100 */) {
this.appBinding = appBinding;
}
}
@Component({selector: 'hello-app', template: ''})
@ -98,7 +76,8 @@ class DummyConsole implements Console {
}
export function main() {
var fakeDoc: any /** TODO #9100 */, el: any /** TODO #9100 */, el2: any /** TODO #9100 */, testProviders: any /** TODO #9100 */, lightDom: any /** TODO #9100 */;
var fakeDoc: any /** TODO #9100 */, el: any /** TODO #9100 */, el2: any /** TODO #9100 */,
testProviders: any /** TODO #9100 */, lightDom: any /** TODO #9100 */;
describe('bootstrap factory method', () => {
beforeEach(() => {
@ -122,14 +101,16 @@ export function main() {
var logger = new _ArrayLogger();
var exceptionHandler = new ExceptionHandler(logger, false);
expect(
() => bootstrap(HelloRootDirectiveIsNotCmp,
[testProviders, {provide: ExceptionHandler, useValue: exceptionHandler}]))
() => bootstrap(
HelloRootDirectiveIsNotCmp,
[testProviders, {provide: ExceptionHandler, useValue: exceptionHandler}]))
.toThrowError(
`Could not compile '${stringify(HelloRootDirectiveIsNotCmp)}' because it is not a component.`);
expect(logger.res.join("")).toContain("Could not compile");
expect(logger.res.join('')).toContain('Could not compile');
});
it('should throw if no element is found', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
it('should throw if no element is found',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var logger = new _ArrayLogger();
var exceptionHandler = new ExceptionHandler(logger, false);
@ -166,7 +147,7 @@ export function main() {
var refPromise =
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
PromiseWrapper.then(refPromise, null, (reason) => {
expect(logger.res.join(""))
expect(logger.res.join(''))
.toContain('The selector "hello-app" did not match any elements');
async.done();
return null;
@ -187,53 +168,53 @@ export function main() {
});
}));
it('should support multiple calls to bootstrap', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
it('should support multiple calls to bootstrap',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var refPromise1 = bootstrap(HelloRootCmp, testProviders);
var refPromise2 = bootstrap(HelloRootCmp2, testProviders);
PromiseWrapper.all([refPromise1, refPromise2])
.then((refs) => {
expect(el).toHaveText('hello world!');
expect(el2).toHaveText('hello world, again!');
async.done();
});
}));
it('should not crash if change detection is invoked when the root component is disposed',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
bootstrap(HelloOnDestroyTickCmp, testProviders)
.then((ref) => {
expect(() => ref.destroy()).not.toThrow();
async.done();
});
}));
it('should unregister change detectors when components are disposed',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var platform = createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PLATFORM_PROVIDERS));
var app =
ReflectiveInjector.resolveAndCreate([BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS, testProviders],
platform.injector)
.get(ApplicationRef);
coreLoadAndBootstrap(HelloRootCmp, app.injector)
.then((ref) => {
ref.destroy();
expect(() => app.tick()).not.toThrow();
async.done();
});
}));
it("should make the provided bindings available to the application component",
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var refPromise = bootstrap(
HelloRootCmp3, [testProviders, {provide: "appBinding", useValue: "BoundValue"}]);
refPromise.then((ref) => {
expect(ref.instance.appBinding).toEqual("BoundValue");
PromiseWrapper.all([refPromise1, refPromise2]).then((refs) => {
expect(el).toHaveText('hello world!');
expect(el2).toHaveText('hello world, again!');
async.done();
});
}));
it("should avoid cyclic dependencies when root component requires Lifecycle through DI",
it('should not crash if change detection is invoked when the root component is disposed',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
bootstrap(HelloOnDestroyTickCmp, testProviders).then((ref) => {
expect(() => ref.destroy()).not.toThrow();
async.done();
});
}));
it('should unregister change detectors when components are disposed',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var platform =
createPlatform(ReflectiveInjector.resolveAndCreate(BROWSER_PLATFORM_PROVIDERS));
var app = ReflectiveInjector
.resolveAndCreate(
[BROWSER_APP_PROVIDERS, BROWSER_APP_COMPILER_PROVIDERS, testProviders],
platform.injector)
.get(ApplicationRef);
coreLoadAndBootstrap(HelloRootCmp, app.injector).then((ref) => {
ref.destroy();
expect(() => app.tick()).not.toThrow();
async.done();
});
}));
it('should make the provided bindings available to the application component',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var refPromise = bootstrap(
HelloRootCmp3, [testProviders, {provide: 'appBinding', useValue: 'BoundValue'}]);
refPromise.then((ref) => {
expect(ref.instance.appBinding).toEqual('BoundValue');
async.done();
});
}));
it('should avoid cyclic dependencies when root component requires Lifecycle through DI',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var refPromise = bootstrap(HelloRootCmp4, testProviders);
@ -243,24 +224,24 @@ export function main() {
});
}));
it("should run platform initializers", inject([Log], (log: Log) => {
it('should run platform initializers', inject([Log], (log: Log) => {
let p = createPlatform(ReflectiveInjector.resolveAndCreate([
BROWSER_PLATFORM_PROVIDERS,
{provide: PLATFORM_INITIALIZER, useValue: log.fn("platform_init1"), multi: true},
{provide: PLATFORM_INITIALIZER, useValue: log.fn("platform_init2"), multi: true}
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init1'), multi: true},
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init2'), multi: true}
]));
expect(log.result()).toEqual("platform_init1; platform_init2");
expect(log.result()).toEqual('platform_init1; platform_init2');
log.clear();
var a = ReflectiveInjector.resolveAndCreate(
[
BROWSER_APP_PROVIDERS,
{provide: APP_INITIALIZER, useValue: log.fn("app_init1"), multi: true},
{provide: APP_INITIALIZER, useValue: log.fn("app_init2"), multi: true}
{provide: APP_INITIALIZER, useValue: log.fn('app_init1'), multi: true},
{provide: APP_INITIALIZER, useValue: log.fn('app_init2'), multi: true}
],
p.injector);
a.get(ApplicationRef);
expect(log.result()).toEqual("app_init1; app_init2");
expect(log.result()).toEqual('app_init1; app_init2');
}));
it('should register each application with the testability registry',
@ -268,18 +249,16 @@ export function main() {
var refPromise1: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp, testProviders);
var refPromise2: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp2, testProviders);
PromiseWrapper.all([refPromise1, refPromise2])
.then((refs: ComponentRef<any>[]) => {
var registry = refs[0].injector.get(TestabilityRegistry);
var testabilities =
[refs[0].injector.get(Testability), refs[1].injector.get(Testability)];
PromiseWrapper.all(testabilities)
.then((testabilities: Testability[]) => {
expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]);
expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]);
async.done();
});
});
PromiseWrapper.all([refPromise1, refPromise2]).then((refs: ComponentRef<any>[]) => {
var registry = refs[0].injector.get(TestabilityRegistry);
var testabilities =
[refs[0].injector.get(Testability), refs[1].injector.get(Testability)];
PromiseWrapper.all(testabilities).then((testabilities: Testability[]) => {
expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]);
expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]);
async.done();
});
});
}));
});
}

View File

@ -1,17 +1,7 @@
import {
beforeEach,
afterEach,
describe,
ddescribe,
expect,
inject,
it,
iit,
AsyncTestCompleter
} from "@angular/core/testing/testing_internal";
import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {parseCookieValue} from "../../src/browser/browser_adapter";
import {parseCookieValue} from '../../src/browser/browser_adapter';
export function main() {
describe('cookies', () => {

View File

@ -1,3 +1,5 @@
export function createRectangle(left: any /** TODO #9100 */, top: any /** TODO #9100 */, width: any /** TODO #9100 */, height: any /** TODO #9100 */) {
export function createRectangle(
left: any /** TODO #9100 */, top: any /** TODO #9100 */, width: any /** TODO #9100 */,
height: any /** TODO #9100 */) {
return {left, top, width, height};
}

View File

@ -1,6 +1,6 @@
import {ddescribe, describe, it, iit, xit, expect, afterEach} from '@angular/core/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {afterEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing';
import {Title} from '@angular/platform-browser';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
export function main() {
describe('title service', () => {

View File

@ -1,7 +1,8 @@
import {SpyObject} from '@angular/core/testing/testing_internal';
import {ReflectiveInjector, provide} from '@angular/core';
import {global} from '../../../src/facade/lang';
import {ApplicationRef, ApplicationRef_} from '@angular/core/src/application_ref';
import {SpyObject} from '@angular/core/testing/testing_internal';
import {global} from '../../../src/facade/lang';
export class SpyApplicationRef extends SpyObject {
constructor() { super(ApplicationRef_); }

View File

@ -1,16 +1,6 @@
import {
afterEach,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit
} from '@angular/core/testing/testing_internal';
import {afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {disableDebugTools, enableDebugTools} from '@angular/platform-browser';
import {enableDebugTools, disableDebugTools} from '@angular/platform-browser';
import {SpyComponentRef, callNgProfilerTimeChangeDetection} from './spies';
export function main() {

View File

@ -1,6 +1,7 @@
import {describe, it, iit, ddescribe, expect} from '@angular/core/testing';
import {BrowserDetection} from '../testing/browser_util';
import {ddescribe, describe, expect, iit, it} from '@angular/core/testing';
import {StringMapWrapper} from '../src/facade/collection';
import {BrowserDetection} from '../testing/browser_util';
export function main() {
describe('BrowserDetection', () => {

View File

@ -1,13 +1,4 @@
import {
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from '@angular/core/testing/testing_internal';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
// import {MapWrapper} from '../../src/facade/src/collection';
// import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';

View File

@ -1,21 +1,9 @@
import {
describe,
ddescribe,
it,
iit,
xit,
xdescribe,
expect,
beforeEach,
} from '@angular/core/testing/testing_internal';
import {describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach,} from '@angular/core/testing/testing_internal';
import {DomEventsPlugin} from '@angular/platform-browser/src/dom/events/dom_events';
import {NgZone} from '@angular/core/src/zone/ng_zone';
import {ListWrapper, Map} from '../../../src/facade/collection';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {
EventManager,
EventManagerPlugin
} from '@angular/platform-browser/src/dom/events/event_manager';
import {EventManager, EventManagerPlugin} from '@angular/platform-browser/src/dom/events/event_manager';
import {el} from '../../../testing/browser_util';
export function main() {
@ -82,7 +70,7 @@ export function main() {
var handler = (e: any /** TODO #9100 */) => { receivedEvent = e; };
var manager = new EventManager([domEventPlugin], new FakeNgZone());
var remover = manager.addGlobalEventListener("document", 'click', handler);
var remover = manager.addGlobalEventListener('document', 'click', handler);
getDOM().dispatchEvent(element, dispatchedEvent);
expect(receivedEvent).toBe(dispatchedEvent);

View File

@ -1,13 +1,4 @@
import {
describe,
ddescribe,
it,
iit,
xit,
xdescribe,
expect,
beforeEach,
} from '@angular/core/testing/testing_internal';
import {describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach,} from '@angular/core/testing/testing_internal';
import {KeyEventsPlugin} from '@angular/platform-browser/src/dom/events/key_events';
export function main() {

View File

@ -1,15 +1,4 @@
import {
beforeEach,
ddescribe,
xdescribe,
describe,
expect,
iit,
inject,
beforeEachProviders,
it,
xit,
} from '@angular/core/testing/testing_internal';
import {beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {DomSharedStylesHost} from '@angular/platform-browser/src/dom/shared_styles_host';

View File

@ -1,21 +1,8 @@
import {
AsyncTestCompleter,
beforeEach,
ddescribe,
xdescribe,
describe,
expect,
iit,
inject,
it,
xit,
beforeEachProviders,
MockAnimationPlayer
} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter, MockAnimationPlayer, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {isPresent} from "../../src/facade/lang";
import {WebAnimationsPlayer} from '../../src/dom/web_animations_player';
import {DomAnimatePlayer} from '../../src/dom/dom_animate_player';
import {WebAnimationsPlayer} from '../../src/dom/web_animations_player';
import {isPresent} from '../../src/facade/lang';
export class MockDomAnimatePlayer implements DomAnimatePlayer {
public captures: {[key: string]: any[]} = {};
@ -131,24 +118,23 @@ export function main() {
expect(count).toEqual(2);
});
it('should destroy itself automatically if a parent player is not present',
() => {
captures['cancel'] = [];
player.finish();
it('should destroy itself automatically if a parent player is not present', () => {
captures['cancel'] = [];
player.finish();
expect(captures['finish'].length).toEqual(1);
expect(captures['cancel'].length).toEqual(1);
expect(captures['finish'].length).toEqual(1);
expect(captures['cancel'].length).toEqual(1);
var next = makePlayer();
var player2 = next['player'];
player2.parentPlayer = new MockAnimationPlayer();
var next = makePlayer();
var player2 = next['player'];
player2.parentPlayer = new MockAnimationPlayer();
var captures2 = next['captures'];
captures2['cancel'] = [];
var captures2 = next['captures'];
captures2['cancel'] = [];
player2.finish();
expect(captures2['finish'].length).toEqual(1);
expect(captures2['cancel'].length).toEqual(0);
});
player2.finish();
expect(captures2['finish'].length).toEqual(1);
expect(captures2['cancel'].length).toEqual(0);
});
});
}

View File

@ -24,8 +24,9 @@ export function main() {
t.it('serializes self closing elements', () => {
t.expect(sanitizeHtml('<p>Hello <br> World</p>')).toEqual('<p>Hello <br> World</p>');
});
t.it('supports namespaced elements',
() => { t.expect(sanitizeHtml('a<my:hr/><my:div>b</my:div>c')).toEqual('abc'); });
t.it('supports namespaced elements', () => {
t.expect(sanitizeHtml('a<my:hr/><my:div>b</my:div>c')).toEqual('abc');
});
t.it('supports namespaced attributes', () => {
t.expect(sanitizeHtml('<a xlink:href="something">t</a>'))
.toEqual('<a xlink:href="something">t</a>');
@ -34,8 +35,9 @@ export function main() {
.toEqual('<a xlink:href="unsafe:javascript:foo()">t</a>');
});
t.it('supports sanitizing plain text',
() => { t.expect(sanitizeHtml('Hello, World')).toEqual('Hello, World'); });
t.it('supports sanitizing plain text', () => {
t.expect(sanitizeHtml('Hello, World')).toEqual('Hello, World');
});
t.it('ignores non-element, non-attribute nodes', () => {
t.expect(sanitizeHtml('<!-- comments? -->no.')).toEqual('no.');
t.expect(sanitizeHtml('<?pi nodes?>no.')).toEqual('no.');
@ -49,36 +51,25 @@ export function main() {
});
t.describe('should strip dangerous elements', () => {
let dangerousTags = [
'frameset',
'form',
'param',
'object',
'embed',
'textarea',
'input',
'button',
'option',
'select',
'script',
'style',
'link',
'base',
'basefont'
'frameset', 'form', 'param', 'object', 'embed', 'textarea', 'input', 'button', 'option',
'select', 'script', 'style', 'link', 'base', 'basefont'
];
for (let tag of dangerousTags) {
t.it(`${tag}`,
() => { t.expect(sanitizeHtml(`<${tag}>evil!</${tag}>`)).toEqual('evil!'); });
t.it(
`${tag}`, () => { t.expect(sanitizeHtml(`<${tag}>evil!</${tag}>`)).toEqual('evil!'); });
}
t.it(`swallows frame entirely`,
() => { t.expect(sanitizeHtml(`<frame>evil!</frame>`)).not.toContain('<frame>'); });
t.it(`swallows frame entirely`, () => {
t.expect(sanitizeHtml(`<frame>evil!</frame>`)).not.toContain('<frame>');
});
});
t.describe('should strip dangerous attributes', () => {
let dangerousAttrs = ['id', 'name', 'style'];
for (let attr of dangerousAttrs) {
t.it(`${attr}`,
() => { t.expect(sanitizeHtml(`<a ${attr}="x">evil!</a>`)).toEqual('<a>evil!</a>'); });
t.it(`${attr}`, () => {
t.expect(sanitizeHtml(`<a ${attr}="x">evil!</a>`)).toEqual('<a>evil!</a>');
});
}
});

View File

@ -1,22 +1,5 @@
import {
it,
iit,
xit,
describe,
ddescribe,
xdescribe,
expect,
beforeEach,
beforeEachProviders,
inject,
} from '@angular/core/testing';
import {
async,
fakeAsync,
flushMicrotasks,
Log,
tick,
} from '@angular/core/testing';
import {it, iit, xit, describe, ddescribe, xdescribe, expect, beforeEach, beforeEachProviders, inject,} from '@angular/core/testing';
import {async, fakeAsync, flushMicrotasks, Log, tick,} from '@angular/core/testing';
import {ROUTER_FAKE_PROVIDERS} from '@angular/router/testing';
import {ROUTER_DIRECTIVES, Routes, Route} from '@angular/router';
@ -50,7 +33,8 @@ class BadTemplateUrl {
@Component({
selector: 'test-router-cmp',
template: `<a [routerLink]="['One']">one</a> <a [routerLink]="['Two']">two</a><router-outlet></router-outlet>`,
template:
`<a [routerLink]="['One']">one</a> <a [routerLink]="['Two']">two</a><router-outlet></router-outlet>`,
directives: [ROUTER_DIRECTIVES]
})
@Routes([
@ -125,7 +109,8 @@ export function main() {
it('provides a real XHR instance',
inject([XHR], (xhr: XHR) => { expect(xhr).toBeAnInstanceOf(XHRImpl); }));
it('should allow the use of fakeAsync', fakeAsync(inject([FancyService], (service: any /** TODO #9100 */) => {
it('should allow the use of fakeAsync',
fakeAsync(inject([FancyService], (service: any /** TODO #9100 */) => {
var value: any /** TODO #9100 */;
service.getAsyncValue().then(function(val: any /** TODO #9100 */) { value = val; });
tick();
@ -155,29 +140,32 @@ export function main() {
var itPromise = patchJasmineIt();
it('should fail with an error from a promise',
async(inject([TestComponentBuilder],
(tcb: TestComponentBuilder) => { return tcb.createAsync(BadTemplateUrl); })));
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb.createAsync(BadTemplateUrl);
})));
itPromise.then(() => { done.fail('Expected test to fail, but it did not'); }, (err) => {
expect(err).toEqual('Uncaught (in promise): Failed to load non-existant.html');
done();
});
itPromise.then(
() => { done.fail('Expected test to fail, but it did not'); },
(err) => {
expect(err).toEqual('Uncaught (in promise): Failed to load non-existant.html');
done();
});
restoreJasmineIt();
}, 10000);
});
describe('test component builder', function() {
it('should allow an external templateUrl',
async(inject([TestComponentBuilder],
(tcb: TestComponentBuilder) => {
async(inject(
[TestComponentBuilder],
(tcb: TestComponentBuilder) => {
tcb.createAsync(ExternalTemplateComp)
.then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText('from external template\n');
});
})),
tcb.createAsync(ExternalTemplateComp).then((componentFixture) => {
componentFixture.detectChanges();
expect(componentFixture.debugElement.nativeElement)
.toHaveText('from external template\n');
});
})),
10000); // Long timeout here because this test makes an actual XHR, and is slow on Edge.
});
});
@ -187,8 +175,9 @@ export function main() {
it('should build without a problem',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.createAsync(TestRouterComponent)
.then((fixture) => { expect(fixture.nativeElement).toHaveText('one two'); });
tcb.createAsync(TestRouterComponent).then((fixture) => {
expect(fixture.nativeElement).toHaveText('one two');
});
})));
});
}

View File

@ -1,21 +1,6 @@
import {
it,
iit,
xit,
describe,
ddescribe,
xdescribe,
expect,
beforeEach,
inject,
beforeEachProviders
} from '@angular/core/testing';
import {
fakeAsync,
async,
withProviders,
tick,
} from '@angular/core/testing';
import {beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing';
import {fakeAsync, async, withProviders, tick,} from '@angular/core/testing';
import {TestComponentBuilder} from '@angular/compiler/testing';
import {Injectable, provide, Component, ViewMetadata} from '@angular/core';
import {NgIf} from '@angular/common';
@ -136,15 +121,20 @@ export function main() {
describe('setting up Providers', () => {
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
it('should use set up providers',
inject([FancyService], (service: any /** TODO #9100 */) => { expect(service.value).toEqual('real value'); }));
it('should use set up providers', inject([FancyService], (service: any /** TODO #9100 */) => {
expect(service.value).toEqual('real value');
}));
it('should wait until returned promises', async(inject([FancyService], (service: any /** TODO #9100 */) => {
service.getAsyncValue().then((value: any /** TODO #9100 */) => { expect(value).toEqual('async value'); });
service.getTimeoutValue().then((value: any /** TODO #9100 */) => { expect(value).toEqual('timeout value'); });
it('should wait until returned promises',
async(inject([FancyService], (service: any /** TODO #9100 */) => {
service.getAsyncValue().then(
(value: any /** TODO #9100 */) => { expect(value).toEqual('async value'); });
service.getTimeoutValue().then(
(value: any /** TODO #9100 */) => { expect(value).toEqual('timeout value'); });
})));
it('should allow the use of fakeAsync', fakeAsync(inject([FancyService], (service: any /** TODO #9100 */) => {
it('should allow the use of fakeAsync',
fakeAsync(inject([FancyService], (service: any /** TODO #9100 */) => {
var value: any /** TODO #9100 */;
service.getAsyncValue().then(function(val: any /** TODO #9100 */) { value = val; });
tick();
@ -165,29 +155,35 @@ export function main() {
});
describe('using beforeEach', () => {
beforeEach(inject([FancyService],
(service: any /** TODO #9100 */) => { service.value = 'value modified in beforeEach'; }));
beforeEach(inject([FancyService], (service: any /** TODO #9100 */) => {
service.value = 'value modified in beforeEach';
}));
it('should use modified providers', inject([FancyService], (service: any /** TODO #9100 */) => {
it('should use modified providers',
inject([FancyService], (service: any /** TODO #9100 */) => {
expect(service.value).toEqual('value modified in beforeEach');
}));
});
describe('using async beforeEach', () => {
beforeEach(async(inject([FancyService], (service: any /** TODO #9100 */) => {
service.getAsyncValue().then((value: any /** TODO #9100 */) => { service.value = value; });
service.getAsyncValue().then(
(value: any /** TODO #9100 */) => { service.value = value; });
})));
it('should use asynchronously modified value',
inject([FancyService], (service: any /** TODO #9100 */) => { expect(service.value).toEqual('async value'); }));
inject([FancyService], (service: any /** TODO #9100 */) => {
expect(service.value).toEqual('async value');
}));
});
});
describe('per test providers', () => {
it('should allow per test providers',
withProviders(() => [{provide: FancyService, useValue: new FancyService()}])
.inject([FancyService],
(service: any /** TODO #9100 */) => { expect(service.value).toEqual('real value'); }));
.inject([FancyService], (service: any /** TODO #9100 */) => {
expect(service.value).toEqual('real value');
}));
it('should return value from inject', () => {
let retval = withProviders(() => [{provide: FancyService, useValue: new FancyService()}])
@ -239,10 +235,12 @@ export function main() {
it('throws an async error',
async(inject([], () => { setTimeout(() => { throw new Error('bar'); }, 0); })));
itPromise.then(() => { done.fail('Expected test to fail, but it did not'); }, (err) => {
expect(err).toEqual('bar');
done();
});
itPromise.then(
() => { done.fail('Expected test to fail, but it did not'); },
(err) => {
expect(err).toEqual('bar');
done();
});
restoreJasmineIt();
});
@ -257,18 +255,21 @@ export function main() {
return p;
})));
itPromise.then(() => { done.fail('Expected test to fail, but it did not'); }, (err) => {
expect(err).toEqual('Uncaught (in promise): baz');
done();
});
itPromise.then(
() => { done.fail('Expected test to fail, but it did not'); },
(err) => {
expect(err).toEqual('Uncaught (in promise): baz');
done();
});
restoreJasmineIt();
});
describe('using beforeEachProviders', () => {
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
beforeEach(
inject([FancyService], (service: any /** TODO #9100 */) => { expect(service.value).toEqual('real value'); }));
beforeEach(inject([FancyService], (service: any /** TODO #9100 */) => {
expect(service.value).toEqual('real value');
}));
describe('nested beforeEachProviders', () => {
@ -277,8 +278,9 @@ export function main() {
expect(() => {
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
})
.toThrowError('beforeEachProviders was called after the injector had been used ' +
'in a beforeEach or it block. This invalidates the test injector');
.toThrowError(
'beforeEachProviders was called after the injector had been used ' +
'in a beforeEach or it block. This invalidates the test injector');
restoreJasmineBeforeEach();
});
});
@ -324,8 +326,8 @@ export function main() {
it('should override a view',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideView(ChildComp,
new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'}))
tcb.overrideView(
ChildComp, new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'}))
.createAsync(ChildComp)
.then((componentFixture) => {
componentFixture.detectChanges();
@ -347,7 +349,7 @@ export function main() {
})));
it("should override child component's dependencies",
it('should override child component\'s dependencies',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideDirective(ParentComp, ChildComp, ChildWithChildComp)
@ -364,7 +366,8 @@ export function main() {
it('should override a provider',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideProviders(TestProvidersComp, [{provide: FancyService, useClass: MockFancyService}])
tcb.overrideProviders(
TestProvidersComp, [{provide: FancyService, useClass: MockFancyService}])
.createAsync(TestProvidersComp)
.then((componentFixture) => {
componentFixture.detectChanges();
@ -377,8 +380,8 @@ export function main() {
it('should override a viewProvider',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideViewProviders(TestViewProvidersComp,
[{provide: FancyService, useClass: MockFancyService}])
tcb.overrideViewProviders(
TestViewProvidersComp, [{provide: FancyService, useClass: MockFancyService}])
.createAsync(TestViewProvidersComp)
.then((componentFixture) => {
componentFixture.detectChanges();

View File

@ -1,11 +1,4 @@
import {
inject,
describe,
it,
expect,
beforeEach,
beforeEachProviders,
} from '@angular/core/testing/testing_internal';
import {inject, describe, it, expect, beforeEach, beforeEachProviders,} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {ObservableWrapper, TimerWrapper} from '../../../src/facade/async';
import {MessageBus} from '@angular/platform-browser/src/web_workers/shared/message_bus';
@ -18,15 +11,15 @@ export function main() {
/**
* Tests the PostMessageBus in TypeScript and the IsolateMessageBus in Dart
*/
describe("MessageBus", () => {
describe('MessageBus', () => {
var bus: MessageBus;
beforeEach(() => { bus = createConnectedMessageBus(); });
it("should pass messages in the same channel from sink to source",
it('should pass messages in the same channel from sink to source',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const CHANNEL = "CHANNEL 1";
const MESSAGE = "Test message";
const CHANNEL = 'CHANNEL 1';
const MESSAGE = 'Test message';
bus.initChannel(CHANNEL, false);
var fromEmitter = bus.from(CHANNEL);
@ -38,9 +31,9 @@ export function main() {
ObservableWrapper.callEmit(toEmitter, MESSAGE);
}));
it("should broadcast", inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const CHANNEL = "CHANNEL 1";
const MESSAGE = "TESTING";
it('should broadcast', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const CHANNEL = 'CHANNEL 1';
const MESSAGE = 'TESTING';
const NUM_LISTENERS = 2;
bus.initChannel(CHANNEL, false);
@ -62,11 +55,12 @@ export function main() {
ObservableWrapper.callEmit(toEmitter, MESSAGE);
}));
it("should keep channels independent", inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const CHANNEL_ONE = "CHANNEL 1";
const CHANNEL_TWO = "CHANNEL 2";
const MESSAGE_ONE = "This is a message on CHANNEL 1";
const MESSAGE_TWO = "This is a message on CHANNEL 2";
it('should keep channels independent',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const CHANNEL_ONE = 'CHANNEL 1';
const CHANNEL_TWO = 'CHANNEL 2';
const MESSAGE_ONE = 'This is a message on CHANNEL 1';
const MESSAGE_TWO = 'This is a message on CHANNEL 2';
var callCount = 0;
bus.initChannel(CHANNEL_ONE, false);
bus.initChannel(CHANNEL_TWO, false);
@ -96,9 +90,9 @@ export function main() {
}));
});
describe("PostMessageBusSink", () => {
describe('PostMessageBusSink', () => {
var bus: MessageBus;
const CHANNEL = "Test Channel";
const CHANNEL = 'Test Channel';
function setup(runInZone: boolean, zone: NgZone) {
bus.attachToZone(zone);
@ -111,39 +105,39 @@ export function main() {
// TODO(mlaval): timeout is fragile, test to be rewritten
function flushMessages(fn: () => void) { TimerWrapper.setTimeout(fn, 50); }
it("should buffer messages and wait for the zone to exit before sending",
it('should buffer messages and wait for the zone to exit before sending',
withProviders(() => [{provide: NgZone, useClass: MockNgZone}])
.inject([AsyncTestCompleter, NgZone],
(async: AsyncTestCompleter, zone: MockNgZone) => {
bus = createConnectedMessageBus();
setup(true, zone);
.inject(
[AsyncTestCompleter, NgZone],
(async: AsyncTestCompleter, zone: MockNgZone) => {
bus = createConnectedMessageBus();
setup(true, zone);
var wasCalled = false;
ObservableWrapper.subscribe(bus.from(CHANNEL),
(message) => { wasCalled = true; });
ObservableWrapper.callEmit(bus.to(CHANNEL), "hi");
var wasCalled = false;
ObservableWrapper.subscribe(bus.from(CHANNEL), (message) => { wasCalled = true; });
ObservableWrapper.callEmit(bus.to(CHANNEL), 'hi');
flushMessages(() => {
expect(wasCalled).toBeFalsy();
flushMessages(() => {
expect(wasCalled).toBeFalsy();
zone.simulateZoneExit();
flushMessages(() => {
expect(wasCalled).toBeTruthy();
async.done();
});
});
}),
zone.simulateZoneExit();
flushMessages(() => {
expect(wasCalled).toBeTruthy();
async.done();
});
});
}),
500);
it("should send messages immediatly when run outside the zone",
it('should send messages immediatly when run outside the zone',
inject([AsyncTestCompleter, NgZone], (async: AsyncTestCompleter, zone: MockNgZone) => {
bus = createConnectedMessageBus();
setup(false, zone);
var wasCalled = false;
ObservableWrapper.subscribe(bus.from(CHANNEL), (message) => { wasCalled = true; });
ObservableWrapper.callEmit(bus.to(CHANNEL), "hi");
ObservableWrapper.callEmit(bus.to(CHANNEL), 'hi');
flushMessages(() => {
expect(wasCalled).toBeTruthy();

View File

@ -1,9 +1,6 @@
import {
PostMessageBusSource,
PostMessageBusSink,
PostMessageBus
} from '@angular/platform-browser/src/web_workers/shared/post_message_bus';
import {MessageBus} from '@angular/platform-browser/src/web_workers/shared/message_bus';
import {PostMessageBus, PostMessageBusSink, PostMessageBusSource} from '@angular/platform-browser/src/web_workers/shared/post_message_bus';
/*
* Returns a PostMessageBus thats sink is connected to its own source.
@ -21,10 +18,10 @@ class MockPostMessage {
private _listener: EventListener;
addEventListener(type: string, listener: EventListener, useCapture?: boolean): void {
if (type === "message") {
if (type === 'message') {
this._listener = listener;
}
}
postMessage(data: any, transfer?:[ArrayBuffer]): void { this._listener(<any>{data: data}); }
postMessage(data: any, transfer?: [ArrayBuffer]): void { this._listener(<any>{data: data}); }
}

View File

@ -1,15 +1,8 @@
import {
inject,
describe,
ddescribe,
beforeEach,
it,
expect
} from '@angular/core/testing/testing_internal';
import {beforeEach, ddescribe, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/render_store';
export function main() {
describe("RenderStoreSpec", () => {
describe('RenderStoreSpec', () => {
var store: RenderStore;
beforeEach(() => { store = new RenderStore(); });

View File

@ -1,35 +1,24 @@
import {
inject,
describe,
it,
iit,
expect,
beforeEach,
beforeEachProviders,
} from '@angular/core/testing/testing_internal';
import {inject, describe, it, iit, expect, beforeEach, beforeEachProviders,} from '@angular/core/testing/testing_internal';
import {browserDetection} from '@angular/platform-browser/testing';
import {createPairedMessageBuses} from './web_worker_test_util';
import {Serializer, PRIMITIVE} from '@angular/platform-browser/src/web_workers/shared/serializer';
import {
ServiceMessageBroker,
ServiceMessageBroker_
} from '@angular/platform-browser/src/web_workers/shared/service_message_broker';
import {ServiceMessageBroker, ServiceMessageBroker_} from '@angular/platform-browser/src/web_workers/shared/service_message_broker';
import {ObservableWrapper, PromiseWrapper} from '../../../src/facade/async';
import {provide} from '@angular/core';
import {ON_WEB_WORKER} from '@angular/platform-browser/src/web_workers/shared/api';
import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/render_store';
export function main() {
const CHANNEL = "UIMessageBroker Test Channel";
const TEST_METHOD = "TEST_METHOD";
const CHANNEL = 'UIMessageBroker Test Channel';
const TEST_METHOD = 'TEST_METHOD';
const PASSED_ARG_1 = 5;
const PASSED_ARG_2 = 'TEST';
const RESULT = 20;
const ID = "methodId";
const ID = 'methodId';
beforeEachProviders(() => [Serializer, {provide: ON_WEB_WORKER, useValue: true}, RenderStore]);
describe("UIMessageBroker", () => {
describe('UIMessageBroker', () => {
var messageBuses: any /** TODO #9100 */;
beforeEach(() => {
@ -37,30 +26,32 @@ export function main() {
messageBuses.ui.initChannel(CHANNEL);
messageBuses.worker.initChannel(CHANNEL);
});
it("should call registered method with correct arguments",
it('should call registered method with correct arguments',
inject([Serializer], (serializer: Serializer) => {
var broker = new ServiceMessageBroker_(messageBuses.ui, serializer, CHANNEL);
broker.registerMethod(TEST_METHOD, [PRIMITIVE, PRIMITIVE], (arg1, arg2) => {
expect(arg1).toEqual(PASSED_ARG_1);
expect(arg2).toEqual(PASSED_ARG_2);
});
ObservableWrapper.callEmit(messageBuses.worker.to(CHANNEL),
{'method': TEST_METHOD, 'args': [PASSED_ARG_1, PASSED_ARG_2]});
ObservableWrapper.callEmit(
messageBuses.worker.to(CHANNEL),
{'method': TEST_METHOD, 'args': [PASSED_ARG_1, PASSED_ARG_2]});
}));
// TODO(pkozlowski): this fails only in Edge with
// "No provider for RenderStore! (Serializer -> RenderStore)"
if (!browserDetection.isEdge) {
it("should return promises to the worker", inject([Serializer], (serializer: Serializer) => {
it('should return promises to the worker', inject([Serializer], (serializer: Serializer) => {
var broker = new ServiceMessageBroker_(messageBuses.ui, serializer, CHANNEL);
broker.registerMethod(TEST_METHOD, [PRIMITIVE], (arg1) => {
expect(arg1).toEqual(PASSED_ARG_1);
return PromiseWrapper.wrap(() => { return RESULT; });
});
ObservableWrapper.callEmit(messageBuses.worker.to(CHANNEL),
{'method': TEST_METHOD, 'id': ID, 'args': [PASSED_ARG_1]});
ObservableWrapper.callEmit(
messageBuses.worker.to(CHANNEL),
{'method': TEST_METHOD, 'id': ID, 'args': [PASSED_ARG_1]});
ObservableWrapper.subscribe(messageBuses.worker.from(CHANNEL), (data: any) => {
expect(data.type).toEqual("result");
expect(data.type).toEqual('result');
expect(data.id).toEqual(ID);
expect(data.value).toEqual(RESULT);
});

View File

@ -1,21 +1,16 @@
import {StringMapWrapper, ListWrapper} from '../../../src/facade/collection';
import {PromiseWrapper} from '../../../src/facade/async';
import {NgZone} from '@angular/core/src/zone/ng_zone';
import {expect} from '@angular/core/testing';
import {UiArguments} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
import {ClientMessageBroker, ClientMessageBrokerFactory_} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
import {MessageBus, MessageBusSink, MessageBusSource} from '@angular/platform-browser/src/web_workers/shared/message_bus';
import {PromiseWrapper} from '../../../src/facade/async';
import {ListWrapper, StringMapWrapper} from '../../../src/facade/collection';
import {BaseException, WrappedException} from '../../../src/facade/exceptions';
import {Type, isPresent} from '../../../src/facade/lang';
import {SpyMessageBroker} from '../worker/spies';
import {expect} from '@angular/core/testing';
import {
MessageBusSink,
MessageBusSource,
MessageBus
} from '@angular/platform-browser/src/web_workers/shared/message_bus';
import {
ClientMessageBroker,
ClientMessageBrokerFactory_
} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
import {MockEventEmitter} from './mock_event_emitter';
import {BaseException, WrappedException} from '../../../src/facade/exceptions';
import {NgZone} from '@angular/core/src/zone/ng_zone';
var __unused: Promise<any>; // avoid unused import when Promise union types are erased
@ -32,8 +27,9 @@ export function createPairedMessageBuses(): PairedMessageBuses {
var uiMessageBusSink = new MockMessageBusSink(secondChannels);
var workerMessageBusSource = new MockMessageBusSource(secondChannels);
return new PairedMessageBuses(new MockMessageBus(uiMessageBusSink, uiMessageBusSource),
new MockMessageBus(workerMessageBusSink, workerMessageBusSource));
return new PairedMessageBuses(
new MockMessageBus(uiMessageBusSink, uiMessageBusSource),
new MockMessageBus(workerMessageBusSink, workerMessageBusSource));
}
/**
@ -42,29 +38,29 @@ export function createPairedMessageBuses(): PairedMessageBuses {
* If a handler is provided it will be called to handle the request.
* Only intended to be called on a given broker instance once.
*/
export function expectBrokerCall(broker: SpyMessageBroker, methodName: string, vals?: Array<any>,
handler?: (..._: any[]) => Promise<any>| void): void {
broker.spy("runOnService")
.andCallFake((args: UiArguments, returnType: Type) => {
expect(args.method).toEqual(methodName);
if (isPresent(vals)) {
expect(args.args.length).toEqual(vals.length);
ListWrapper.forEachWithIndex(vals, (v, i) => {expect(v).toEqual(args.args[i].value)});
}
var promise: any /** TODO #9100 */ = null;
if (isPresent(handler)) {
let givenValues = args.args.map((arg) => {arg.value});
if (givenValues.length > 0) {
promise = handler(givenValues);
} else {
promise = handler();
}
}
if (promise == null) {
promise = PromiseWrapper.wrap(() => {});
}
return promise;
});
export function expectBrokerCall(
broker: SpyMessageBroker, methodName: string, vals?: Array<any>,
handler?: (..._: any[]) => Promise<any>| void): void {
broker.spy('runOnService').andCallFake((args: UiArguments, returnType: Type) => {
expect(args.method).toEqual(methodName);
if (isPresent(vals)) {
expect(args.args.length).toEqual(vals.length);
ListWrapper.forEachWithIndex(vals, (v, i) => {expect(v).toEqual(args.args[i].value)});
}
var promise: any /** TODO #9100 */ = null;
if (isPresent(handler)) {
let givenValues = args.args.map((arg) => {arg.value});
if (givenValues.length > 0) {
promise = handler(givenValues);
} else {
promise = handler();
}
}
if (promise == null) {
promise = PromiseWrapper.wrap(() => {});
}
return promise;
});
}
export class PairedMessageBuses {

View File

@ -1,53 +1,41 @@
import {
inject,
describe,
it,
expect,
beforeEach,
beforeEachProviders
} from '@angular/core/testing/testing_internal';
import {beforeEach, beforeEachProviders, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {SpyMessageBroker} from './spies';
import {
WebWorkerPlatformLocation
} from '@angular/platform-browser/src/web_workers/worker/platform_location';
import {LocationType} from '@angular/platform-browser/src/web_workers/shared/serialized_types';
import {MessageBus} from '@angular/platform-browser/src/web_workers/shared/message_bus';
import {
createPairedMessageBuses,
MockMessageBrokerFactory,
expectBrokerCall
} from '../shared/web_worker_test_util';
import {UiArguments} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
import {Type} from '../../../src/facade/lang';
import {MessageBus} from '@angular/platform-browser/src/web_workers/shared/message_bus';
import {LocationType} from '@angular/platform-browser/src/web_workers/shared/serialized_types';
import {WebWorkerPlatformLocation} from '@angular/platform-browser/src/web_workers/worker/platform_location';
import {PromiseWrapper} from '../../../src/facade/async';
import {Type} from '../../../src/facade/lang';
import {MockMessageBrokerFactory, createPairedMessageBuses, expectBrokerCall} from '../shared/web_worker_test_util';
import {SpyMessageBroker} from './spies';
export function main() {
describe("WebWorkerPlatformLocation", () => {
describe('WebWorkerPlatformLocation', () => {
var uiBus: MessageBus = null;
var workerBus: MessageBus = null;
var broker: any = null;
var TEST_LOCATION =
new LocationType("http://www.example.com", "http", "example.com", "example.com", "80", "/",
"", "", "http://www.example.com");
var TEST_LOCATION = new LocationType(
'http://www.example.com', 'http', 'example.com', 'example.com', '80', '/', '', '',
'http://www.example.com');
function createWebWorkerPlatformLocation(loc: LocationType): WebWorkerPlatformLocation {
broker.spy("runOnService")
.andCallFake((args: UiArguments, returnType: Type) => {
if (args.method === 'getLocation') {
return PromiseWrapper.resolve(loc);
}
});
broker.spy('runOnService').andCallFake((args: UiArguments, returnType: Type) => {
if (args.method === 'getLocation') {
return PromiseWrapper.resolve(loc);
}
});
var factory = new MockMessageBrokerFactory(broker);
return new WebWorkerPlatformLocation(factory, workerBus, null);
}
function testPushOrReplaceState(pushState: boolean) {
let platformLocation = createWebWorkerPlatformLocation(null);
const TITLE = "foo";
const URL = "http://www.example.com/foo";
expectBrokerCall(broker, pushState ? "pushState" : "replaceState", [null, TITLE, URL]);
const TITLE = 'foo';
const URL = 'http://www.example.com/foo';
expectBrokerCall(broker, pushState ? 'pushState' : 'replaceState', [null, TITLE, URL]);
if (pushState) {
platformLocation.pushState(null, TITLE, URL);
} else {
@ -59,40 +47,41 @@ export function main() {
var buses = createPairedMessageBuses();
uiBus = buses.ui;
workerBus = buses.worker;
workerBus.initChannel("ng-Router");
uiBus.initChannel("ng-Router");
workerBus.initChannel('ng-Router');
uiBus.initChannel('ng-Router');
broker = new SpyMessageBroker();
});
it("should throw if getBaseHrefFromDOM is called", () => {
it('should throw if getBaseHrefFromDOM is called', () => {
let platformLocation = createWebWorkerPlatformLocation(null);
expect(() => platformLocation.getBaseHrefFromDOM()).toThrowError();
});
it("should get location on init", () => {
it('should get location on init', () => {
let platformLocation = createWebWorkerPlatformLocation(null);
expectBrokerCall(broker, "getLocation");
expectBrokerCall(broker, 'getLocation');
platformLocation.init();
});
it("should throw if set pathname is called before init finishes", () => {
it('should throw if set pathname is called before init finishes', () => {
let platformLocation = createWebWorkerPlatformLocation(null);
platformLocation.init();
expect(() => platformLocation.pathname = "TEST").toThrowError();
expect(() => platformLocation.pathname = 'TEST').toThrowError();
});
it("should send pathname to render thread", inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
it('should send pathname to render thread',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
let platformLocation = createWebWorkerPlatformLocation(TEST_LOCATION);
platformLocation.init().then((_) => {
let PATHNAME = "/test";
expectBrokerCall(broker, "setPathname", [PATHNAME]);
let PATHNAME = '/test';
expectBrokerCall(broker, 'setPathname', [PATHNAME]);
platformLocation.pathname = PATHNAME;
async.done();
});
}));
it("should send pushState to render thread", () => { testPushOrReplaceState(true); });
it('should send pushState to render thread', () => { testPushOrReplaceState(true); });
it("should send replaceState to render thread", () => { testPushOrReplaceState(false); });
it('should send replaceState to render thread', () => { testPushOrReplaceState(false); });
});
}

View File

@ -1,31 +1,12 @@
import {
inject,
ddescribe,
describe,
it,
iit,
expect,
beforeEach,
beforeEachProviders,
} from '@angular/core/testing/testing_internal';
import {inject, ddescribe, describe, it, iit, expect, beforeEach, beforeEachProviders,} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {TestInjector} from '@angular/core/testing';
import {TestComponentBuilder} from '@angular/compiler/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {
provide,
Injector,
ViewMetadata,
Component,
Injectable,
ComponentRef
} from '@angular/core';
import {provide, Injector, ViewMetadata, Component, Injectable, ComponentRef} from '@angular/core';
import {NgIf} from '@angular/common';
import {WebWorkerRootRenderer} from '@angular/platform-browser/src/web_workers/worker/renderer';
import {
ClientMessageBrokerFactory,
ClientMessageBrokerFactory_
} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
import {ClientMessageBrokerFactory, ClientMessageBrokerFactory_} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
import {Serializer} from '@angular/platform-browser/src/web_workers/shared/serializer';
import {RootRenderer} from '@angular/core/src/render/api';
import {DomRootRenderer, DomRootRenderer_} from '@angular/platform-browser/src/dom/dom_renderer';
@ -33,15 +14,10 @@ import {DebugDomRootRenderer} from '@angular/core/src/debug/debug_renderer';
import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/render_store';
import {MessageBasedRenderer} from '@angular/platform-browser/src/web_workers/ui/renderer';
import {createPairedMessageBuses, PairedMessageBuses} from '../shared/web_worker_test_util';
import {
ServiceMessageBrokerFactory_
} from '@angular/platform-browser/src/web_workers/shared/service_message_broker';
import {ServiceMessageBrokerFactory_} from '@angular/platform-browser/src/web_workers/shared/service_message_broker';
import {CompilerConfig} from '@angular/compiler';
import {dispatchEvent} from '../../../../platform-browser/testing/browser_util';
import {
TEST_BROWSER_PLATFORM_PROVIDERS,
TEST_BROWSER_APPLICATION_PROVIDERS
} from '@angular/platform-browser/testing';
import {TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS} from '@angular/platform-browser/testing';
export function main() {
function createWebWorkerBrokerFactory(
@ -56,25 +32,25 @@ export function main() {
// set up the ui side
var uiMessageBrokerFactory = new ServiceMessageBrokerFactory_(uiMessageBus, uiSerializer);
var renderer = new MessageBasedRenderer(uiMessageBrokerFactory, uiMessageBus, uiSerializer,
uiRenderStore, domRootRenderer);
var renderer = new MessageBasedRenderer(
uiMessageBrokerFactory, uiMessageBus, uiSerializer, uiRenderStore, domRootRenderer);
renderer.start();
return webWorkerBrokerFactory;
}
function createWorkerRenderer(workerSerializer: Serializer, uiSerializer: Serializer,
domRootRenderer: DomRootRenderer, uiRenderStore: RenderStore,
workerRenderStore: RenderStore): RootRenderer {
function createWorkerRenderer(
workerSerializer: Serializer, uiSerializer: Serializer, domRootRenderer: DomRootRenderer,
uiRenderStore: RenderStore, workerRenderStore: RenderStore): RootRenderer {
var messageBuses = createPairedMessageBuses();
var brokerFactory = createWebWorkerBrokerFactory(messageBuses, workerSerializer, uiSerializer,
domRootRenderer, uiRenderStore);
var workerRootRenderer = new WebWorkerRootRenderer(brokerFactory, messageBuses.worker,
workerSerializer, workerRenderStore);
var brokerFactory = createWebWorkerBrokerFactory(
messageBuses, workerSerializer, uiSerializer, domRootRenderer, uiRenderStore);
var workerRootRenderer = new WebWorkerRootRenderer(
brokerFactory, messageBuses.worker, workerSerializer, workerRenderStore);
return new DebugDomRootRenderer(workerRootRenderer);
}
describe("Web Worker Renderer", () => {
describe('Web Worker Renderer', () => {
var uiInjector: Injector;
var uiRenderStore: RenderStore;
var workerRenderStore: RenderStore;
@ -85,8 +61,7 @@ export function main() {
testUiInjector.platformProviders = TEST_BROWSER_PLATFORM_PROVIDERS;
testUiInjector.applicationProviders = TEST_BROWSER_APPLICATION_PROVIDERS;
testUiInjector.addProviders([
Serializer,
{provide: RenderStore, useValue: uiRenderStore},
Serializer, {provide: RenderStore, useValue: uiRenderStore},
{provide: DomRootRenderer, useClass: DomRootRenderer_},
{provide: RootRenderer, useExisting: DomRootRenderer}
]);
@ -95,14 +70,12 @@ export function main() {
var domRootRenderer = uiInjector.get(DomRootRenderer);
workerRenderStore = new RenderStore();
return [
Serializer,
{provide: CompilerConfig, useValue: new CompilerConfig(true, true, false)},
{provide: RenderStore, useValue: workerRenderStore},
{
Serializer, {provide: CompilerConfig, useValue: new CompilerConfig(true, true, false)},
{provide: RenderStore, useValue: workerRenderStore}, {
provide: RootRenderer,
useFactory: (workerSerializer: Serializer) => {
return createWorkerRenderer(workerSerializer, uiSerializer, domRootRenderer,
uiRenderStore, workerRenderStore);
return createWorkerRenderer(
workerSerializer, uiSerializer, domRootRenderer, uiRenderStore, workerRenderStore);
},
deps: [Serializer]
}
@ -119,126 +92,141 @@ export function main() {
}
it('should update text nodes',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2, new ViewMetadata({template: '<div>{{ctxProp}}</div>'}))
.createAsync(MyComp2)
.then((fixture) => {
var renderEl = getRenderElement(fixture.debugElement.nativeElement);
expect(renderEl).toHaveText('');
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2, new ViewMetadata({template: '<div>{{ctxProp}}</div>'}))
.createAsync(MyComp2)
.then((fixture) => {
var renderEl = getRenderElement(fixture.debugElement.nativeElement);
expect(renderEl).toHaveText('');
fixture.debugElement.componentInstance.ctxProp = 'Hello World!';
fixture.detectChanges();
expect(renderEl).toHaveText('Hello World!');
async.done();
fixture.debugElement.componentInstance.ctxProp = 'Hello World!';
fixture.detectChanges();
expect(renderEl).toHaveText('Hello World!');
async.done();
});
}));
});
}));
it('should update any element property/attributes/class/style(s) independent of the compilation on the root element and other elements',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2, new ViewMetadata(
{template: '<input [title]="y" style="position:absolute">'}))
.createAsync(MyComp2)
.then((fixture) => {
var checkSetters = (componentRef: any /** TODO #9100 */, workerEl: any /** TODO #9100 */) => {
var renderer = getRenderer(componentRef);
var el = getRenderElement(workerEl);
renderer.setElementProperty(workerEl, 'tabIndex', 1);
expect((<HTMLInputElement>el).tabIndex).toEqual(1);
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp2,
new ViewMetadata({template: '<input [title]="y" style="position:absolute">'}))
.createAsync(MyComp2)
.then((fixture) => {
var checkSetters =
(componentRef: any /** TODO #9100 */, workerEl: any /** TODO #9100 */) => {
var renderer = getRenderer(componentRef);
var el = getRenderElement(workerEl);
renderer.setElementProperty(workerEl, 'tabIndex', 1);
expect((<HTMLInputElement>el).tabIndex).toEqual(1);
renderer.setElementClass(workerEl, 'a', true);
expect(getDOM().hasClass(el, 'a')).toBe(true);
renderer.setElementClass(workerEl, 'a', false);
expect(getDOM().hasClass(el, 'a')).toBe(false);
renderer.setElementClass(workerEl, 'a', true);
expect(getDOM().hasClass(el, 'a')).toBe(true);
renderer.setElementClass(workerEl, 'a', false);
expect(getDOM().hasClass(el, 'a')).toBe(false);
renderer.setElementStyle(workerEl, 'width', '10px');
expect(getDOM().getStyle(el, 'width')).toEqual('10px');
renderer.setElementStyle(workerEl, 'width', null);
expect(getDOM().getStyle(el, 'width')).toEqual('');
renderer.setElementStyle(workerEl, 'width', '10px');
expect(getDOM().getStyle(el, 'width')).toEqual('10px');
renderer.setElementStyle(workerEl, 'width', null);
expect(getDOM().getStyle(el, 'width')).toEqual('');
renderer.setElementAttribute(workerEl, 'someattr', 'someValue');
expect(getDOM().getAttribute(el, 'someattr')).toEqual('someValue');
};
renderer.setElementAttribute(workerEl, 'someattr', 'someValue');
expect(getDOM().getAttribute(el, 'someattr')).toEqual('someValue');
};
// root element
checkSetters(fixture.componentRef, fixture.debugElement.nativeElement);
// nested elements
checkSetters(fixture.componentRef, fixture.debugElement.children[0].nativeElement);
// root element
checkSetters(fixture.componentRef, fixture.debugElement.nativeElement);
// nested elements
checkSetters(
fixture.componentRef, fixture.debugElement.children[0].nativeElement);
async.done();
});
}));
async.done();
});
}));
it('should update any template comment property/attributes',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
var tpl = '<template [ngIf]="ctxBoolProp"></template>';
tcb.overrideView(MyComp2, new ViewMetadata({template: tpl, directives: [NgIf]}))
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
var tpl = '<template [ngIf]="ctxBoolProp"></template>';
tcb.overrideView(MyComp2, new ViewMetadata({template: tpl, directives: [NgIf]}))
.createAsync(MyComp2)
.then((fixture) => {
(<MyComp2>fixture.debugElement.componentInstance).ctxBoolProp = true;
fixture.detectChanges();
var el = getRenderElement(fixture.debugElement.nativeElement);
expect(getDOM().getInnerHTML(el)).toContain('"ng-reflect-ng-if": "true"');
async.done();
});
}));
.createAsync(MyComp2)
.then((fixture) => {
(<MyComp2>fixture.debugElement.componentInstance).ctxBoolProp = true;
fixture.detectChanges();
var el = getRenderElement(fixture.debugElement.nativeElement);
expect(getDOM().getInnerHTML(el)).toContain('"ng-reflect-ng-if": "true"');
async.done();
});
}));
it('should add and remove fragments',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2, new ViewMetadata({
template: '<template [ngIf]="ctxBoolProp">hello</template>',
directives: [NgIf]
}))
.createAsync(MyComp2)
.then((fixture) => {
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2, new ViewMetadata({
template: '<template [ngIf]="ctxBoolProp">hello</template>',
directives: [NgIf]
}))
.createAsync(MyComp2)
.then((fixture) => {
var rootEl = getRenderElement(fixture.debugElement.nativeElement);
expect(rootEl).toHaveText('');
var rootEl = getRenderElement(fixture.debugElement.nativeElement);
expect(rootEl).toHaveText('');
fixture.debugElement.componentInstance.ctxBoolProp = true;
fixture.detectChanges();
expect(rootEl).toHaveText('hello');
fixture.debugElement.componentInstance.ctxBoolProp = true;
fixture.detectChanges();
expect(rootEl).toHaveText('hello');
fixture.debugElement.componentInstance.ctxBoolProp = false;
fixture.detectChanges();
expect(rootEl).toHaveText('');
fixture.debugElement.componentInstance.ctxBoolProp = false;
fixture.detectChanges();
expect(rootEl).toHaveText('');
async.done();
});
}));
async.done();
});
}));
if (getDOM().supportsDOMEvents()) {
it('should call actions on the element',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2, new ViewMetadata({template: '<input [title]="y">'}))
.createAsync(MyComp2)
.then((fixture) => {
var el = fixture.debugElement.children[0];
getRenderer(fixture.componentRef)
.invokeElementMethod(el.nativeElement, 'setAttribute', ['a', 'b']);
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2, new ViewMetadata({template: '<input [title]="y">'}))
.createAsync(MyComp2)
.then((fixture) => {
var el = fixture.debugElement.children[0];
getRenderer(fixture.componentRef)
.invokeElementMethod(el.nativeElement, 'setAttribute', ['a', 'b']);
expect(getDOM().getAttribute(getRenderElement(el.nativeElement), 'a'))
.toEqual('b');
async.done();
});
}));
expect(getDOM().getAttribute(getRenderElement(el.nativeElement), 'a'))
.toEqual('b');
async.done();
});
}));
it('should listen to events',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp2,
new ViewMetadata({template: '<input (change)="ctxNumProp = 1">'}))
.createAsync(MyComp2)
.then((fixture) => {
var el = fixture.debugElement.children[0];
dispatchEvent(getRenderElement(el.nativeElement), 'change');
expect(fixture.componentInstance.ctxNumProp).toBe(1);
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp2, new ViewMetadata({template: '<input (change)="ctxNumProp = 1">'}))
.createAsync(MyComp2)
.then((fixture) => {
var el = fixture.debugElement.children[0];
dispatchEvent(getRenderElement(el.nativeElement), 'change');
expect(fixture.componentInstance.ctxNumProp).toBe(1);
fixture.destroy();
fixture.destroy();
async.done();
});
}));
async.done();
});
}));
}
});
}

View File

@ -1,8 +1,5 @@
import {
ClientMessageBroker
} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
import {SpyObject, proxy} from '@angular/core/testing/testing_internal';
import {ClientMessageBroker} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
export class SpyMessageBroker extends SpyObject {
constructor() { super(ClientMessageBroker); }

View File

@ -1,23 +1,10 @@
import {Component, provide} from '@angular/core';
import {UrlResolver, XHR} from '@angular/compiler';
import {
beforeEach,
beforeEachProviders,
ddescribe,
describe,
iit,
inject,
it,
xit
} from '@angular/core/testing/testing_internal';
import {expect} from '@angular/platform-browser/testing';
import {Component, provide} from '@angular/core';
import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {
fakeAsync,
flushMicrotasks,
Log,
tick,
} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing';
import {fakeAsync, flushMicrotasks, Log, tick,} from '@angular/core/testing';
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
import {BaseException} from '../../src/facade/exceptions';
import {CachedXHR} from '../../src/xhr/xhr_cache';
@ -31,29 +18,30 @@ export function main() {
setTemplateCache({'test.html': '<div>Hello</div>'});
return new CachedXHR();
}
beforeEachProviders(() => [
{provide: UrlResolver, useClass: TestUrlResolver},
{provide: XHR, useFactory: createCachedXHR}
]);
beforeEachProviders(() => [{provide: UrlResolver, useClass: TestUrlResolver}, {
provide: XHR,
useFactory: createCachedXHR
}]);
it('should throw exception if $templateCache is not found', () => {
setTemplateCache(null);
expect(() => { xhr = new CachedXHR(); })
.toThrowErrorWith('CachedXHR: Template cache was not found in $templateCache.');
expect(() => {
xhr = new CachedXHR();
}).toThrowErrorWith('CachedXHR: Template cache was not found in $templateCache.');
});
it('should resolve the Promise with the cached file content on success',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
setTemplateCache({'test.html': '<div>Hello</div>'});
xhr = new CachedXHR();
xhr.get('test.html')
.then((text) => {
expect(text).toEqual('<div>Hello</div>');
async.done();
});
xhr.get('test.html').then((text) => {
expect(text).toEqual('<div>Hello</div>');
async.done();
});
}));
it('should reject the Promise on failure', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
it('should reject the Promise on failure',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
xhr = new CachedXHR();
xhr.get('unknown.html')
.then((text) => { throw new BaseException('Not expected to succeed.'); })

View File

@ -1,16 +1,7 @@
import {
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
AsyncTestCompleter
} from '@angular/core/testing/testing_internal';
import {XHRImpl} from '../../src/xhr/xhr_impl';
import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {PromiseWrapper} from '../../src/facade/async';
import {XHRImpl} from '../../src/xhr/xhr_impl';
export function main() {
describe('XHRImpl', () => {
@ -35,7 +26,8 @@ export function main() {
});
}), 10000);
it('should reject the Promise on failure', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
it('should reject the Promise on failure',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
PromiseWrapper.catchError(xhr.get(url404), (e) => {
expect(e).toEqual(`Failed to load ${url404}`);
async.done();