committed by
Miško Hevery
parent
ef9e40e82b
commit
14f0e9ada8
@@ -140,7 +140,7 @@ export function main() {
|
||||
]);
|
||||
|
||||
var value = null;
|
||||
c(new Control("invalid")).then(v => value = v);
|
||||
(<Promise<any>>c(new Control("invalid"))).then(v => value = v);
|
||||
|
||||
tick(1);
|
||||
|
||||
@@ -151,7 +151,7 @@ export function main() {
|
||||
var c = Validators.composeAsync([asyncValidator("expected", {"one": true})]);
|
||||
|
||||
var value = null;
|
||||
c(new Control("expected")).then(v => value = v);
|
||||
(<Promise<any>>c(new Control("expected"))).then(v => value = v);
|
||||
|
||||
tick(1);
|
||||
|
||||
@@ -162,7 +162,7 @@ export function main() {
|
||||
var c = Validators.composeAsync([asyncValidator("expected", {"one": true}), null]);
|
||||
|
||||
var value = null;
|
||||
c(new Control("invalid")).then(v => value = v);
|
||||
(<Promise<any>>c(new Control("invalid"))).then(v => value = v);
|
||||
|
||||
tick(1);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
TimerWrapper
|
||||
} from 'angular2/src/facade/async';
|
||||
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
||||
import {PromiseCompleter} from 'angular2/src/facade/promise';
|
||||
|
||||
export function main() {
|
||||
describe("AsyncPipe", () => {
|
||||
@@ -116,16 +117,16 @@ export function main() {
|
||||
|
||||
describe("Promise", () => {
|
||||
var message = new Object();
|
||||
var pipe;
|
||||
var completer;
|
||||
var ref;
|
||||
var pipe: AsyncPipe;
|
||||
var completer: PromiseCompleter<any>;
|
||||
var ref: SpyChangeDetectorRef;
|
||||
// adds longer timers for passing tests in IE
|
||||
var timer = (!isBlank(DOM) && browserDetection.isIE) ? 50 : 0;
|
||||
|
||||
beforeEach(() => {
|
||||
completer = PromiseWrapper.completer();
|
||||
ref = new SpyChangeDetectorRef();
|
||||
pipe = new AsyncPipe(ref);
|
||||
pipe = new AsyncPipe(<any>ref);
|
||||
});
|
||||
|
||||
describe("transform", () => {
|
||||
|
||||
@@ -76,14 +76,15 @@ export function main() {
|
||||
|
||||
describe('compile templates', () => {
|
||||
|
||||
function runTests(compile) {
|
||||
function runTests(compile: (components: Type[]) => Promise<any[]>) {
|
||||
it('should throw for non components', inject([AsyncTestCompleter], (async) => {
|
||||
PromiseWrapper.catchError(PromiseWrapper.wrap(() => compile([NonComponent])), (error) => {
|
||||
expect(error.message)
|
||||
.toEqual(
|
||||
`Could not compile '${stringify(NonComponent)}' because it is not a component.`);
|
||||
async.done();
|
||||
});
|
||||
PromiseWrapper.catchError(
|
||||
PromiseWrapper.wrap(() => compile([NonComponent])), (error): any => {
|
||||
expect(error.message)
|
||||
.toEqual(
|
||||
`Could not compile '${stringify(NonComponent)}' because it is not a component.`);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should compile host components', inject([AsyncTestCompleter], (async) => {
|
||||
|
||||
@@ -99,14 +99,14 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should contain a default value of "/packages" when nothing is provided for DART',
|
||||
inject([UrlResolver], (resolver) => {
|
||||
inject([UrlResolver], (resolver: UrlResolver) => {
|
||||
if (IS_DART) {
|
||||
expect(resolver.resolve(null, 'package:file')).toEqual('/packages/file');
|
||||
}
|
||||
}));
|
||||
|
||||
it('should contain a default value of "/" when nothing is provided for TS/ESM',
|
||||
inject([UrlResolver], (resolver) => {
|
||||
inject([UrlResolver], (resolver: UrlResolver) => {
|
||||
if (!IS_DART) {
|
||||
expect(resolver.resolve(null, 'package:file')).toEqual('/file');
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ export function main() {
|
||||
});
|
||||
}));
|
||||
|
||||
function mockAsyncAppInitializer(completer, providers: Array<any> = null,
|
||||
injector?: Injector) {
|
||||
function mockAsyncAppInitializer(completer: PromiseCompleter<any>,
|
||||
providers: Array<any> = null, injector?: Injector) {
|
||||
return () => {
|
||||
if (providers != null) {
|
||||
expectProviders(injector, providers);
|
||||
@@ -76,23 +76,11 @@ export function main() {
|
||||
};
|
||||
}
|
||||
|
||||
function createSpyPromiseCompleter(): SpyObject {
|
||||
let completer = PromiseWrapper.completer();
|
||||
let completerSpy = <any>new SpyObject();
|
||||
// Note that in TypeScript we need to provide a value for the promise attribute
|
||||
// whereas in dart we need to override the promise getter
|
||||
completerSpy.promise = completer.promise;
|
||||
completerSpy.spy("get:promise").andReturn(completer.promise);
|
||||
completerSpy.spy("resolve").andCallFake(completer.resolve);
|
||||
completerSpy.spy("reject").andCallFake(completer.reject);
|
||||
return completerSpy;
|
||||
}
|
||||
|
||||
it("should wait for asyncronous app initializers",
|
||||
inject([AsyncTestCompleter, Injector], (async, injector) => {
|
||||
let ref = new PlatformRef_(injector, null);
|
||||
|
||||
let completer = createSpyPromiseCompleter();
|
||||
let completer: PromiseCompleter<any> = PromiseWrapper.completer();
|
||||
let SYNC_PROVIDERS = [
|
||||
new Provider(Bar, {useValue: new Bar()}),
|
||||
new Provider(APP_INITIALIZER,
|
||||
@@ -102,8 +90,7 @@ export function main() {
|
||||
.then((appRef) => {
|
||||
expectProviders(appRef.injector,
|
||||
SYNC_PROVIDERS.slice(0, SYNC_PROVIDERS.length - 1));
|
||||
expect(completer.spy("resolve")).toHaveBeenCalled();
|
||||
async.done();
|
||||
completer.promise.then((_) => async.done());
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -111,13 +98,13 @@ export function main() {
|
||||
inject([AsyncTestCompleter, Injector], (async, injector) => {
|
||||
let ref = new PlatformRef_(injector, null);
|
||||
let ASYNC_PROVIDERS = [new Provider(Foo, {useValue: new Foo()})];
|
||||
let completer = createSpyPromiseCompleter();
|
||||
let completer: PromiseCompleter<any> = PromiseWrapper.completer();
|
||||
let SYNC_PROVIDERS = [
|
||||
new Provider(Bar, {useValue: new Bar()}),
|
||||
new Provider(APP_INITIALIZER,
|
||||
{
|
||||
useFactory: (injector) => mockAsyncAppInitializer(
|
||||
completer, ASYNC_PROVIDERS, injector),
|
||||
<any>completer, ASYNC_PROVIDERS, injector),
|
||||
multi: true,
|
||||
deps: [Injector]
|
||||
})
|
||||
@@ -126,8 +113,7 @@ export function main() {
|
||||
.then((appRef) => {
|
||||
expectProviders(appRef.injector,
|
||||
SYNC_PROVIDERS.slice(0, SYNC_PROVIDERS.length - 1));
|
||||
expect(completer.spy("resolve")).toHaveBeenCalled();
|
||||
async.done();
|
||||
completer.promise.then((_) => async.done());
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ import {Compiler} from 'angular2/src/core/linker/compiler';
|
||||
import {reflector, ReflectionInfo} from 'angular2/src/core/reflection/reflection';
|
||||
import {Compiler_} from "angular2/src/core/linker/compiler";
|
||||
import {HostViewFactory} from 'angular2/src/core/linker/view';
|
||||
import {HostViewFactoryRef_} from 'angular2/src/core/linker/view_ref';
|
||||
|
||||
export function main() {
|
||||
describe('Compiler', () => {
|
||||
@@ -31,11 +32,12 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should read the template from an annotation',
|
||||
inject([AsyncTestCompleter, Compiler], (async, compiler) => {
|
||||
inject([AsyncTestCompleter, Compiler], (async, compiler: Compiler) => {
|
||||
compiler.compileInHost(SomeComponent)
|
||||
.then((hostViewFactoryRef) => {
|
||||
.then((hostViewFactoryRef: HostViewFactoryRef_) => {
|
||||
expect(hostViewFactoryRef.internalHostViewFactory).toBe(someHostViewFactory);
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ class SomeDirectiveWithoutMetadata {}
|
||||
|
||||
export function main() {
|
||||
describe("DirectiveResolver", () => {
|
||||
var resolver;
|
||||
var resolver: DirectiveResolver;
|
||||
|
||||
beforeEach(() => { resolver = new DirectiveResolver(); });
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ export function main() {
|
||||
describe("loading into a location", () => {
|
||||
it('should work',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(
|
||||
MyComp,
|
||||
new ViewMetadata(
|
||||
@@ -52,7 +52,7 @@ export function main() {
|
||||
|
||||
it('should return a disposable component ref',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(
|
||||
MyComp,
|
||||
new ViewMetadata(
|
||||
@@ -72,7 +72,7 @@ export function main() {
|
||||
it('should allow to dispose even if the location has been removed',
|
||||
inject(
|
||||
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp, new ViewMetadata({
|
||||
template: '<child-cmp *ngIf="ctxBoolProp"></child-cmp>',
|
||||
directives: [NgIf, ChildComp]
|
||||
@@ -109,7 +109,7 @@ export function main() {
|
||||
it('should update host properties',
|
||||
inject(
|
||||
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(
|
||||
MyComp, new ViewMetadata(
|
||||
{template: '<location #loc></location>', directives: [Location]}))
|
||||
@@ -131,7 +131,7 @@ export function main() {
|
||||
|
||||
it('should leave the view tree in a consistent state if hydration fails',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp, new ViewMetadata({
|
||||
template: '<div><location #loc></location></div>',
|
||||
directives: [Location]
|
||||
@@ -147,13 +147,14 @@ export function main() {
|
||||
expect(error.message).toContain("ThrownInConstructor");
|
||||
expect(() => tc.detectChanges()).not.toThrow();
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw if the variable does not exist',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(
|
||||
MyComp,
|
||||
new ViewMetadata(
|
||||
@@ -169,7 +170,7 @@ export function main() {
|
||||
|
||||
it('should allow to pass projectable nodes',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp,
|
||||
new ViewMetadata({template: '<div #loc></div>', directives: []}))
|
||||
.createAsync(MyComp)
|
||||
@@ -187,7 +188,7 @@ export function main() {
|
||||
it('should throw if not enough projectable nodes are passed in',
|
||||
inject(
|
||||
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp,
|
||||
new ViewMetadata({template: '<div #loc></div>', directives: []}))
|
||||
.createAsync(MyComp)
|
||||
@@ -199,6 +200,7 @@ export function main() {
|
||||
expect(e.message).toContain(
|
||||
`The component ${stringify(DynamicallyLoadedWithNgContent)} has 1 <ng-content> elements, but only 0 slots were provided`);
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}));
|
||||
@@ -208,7 +210,7 @@ export function main() {
|
||||
describe("loading next to a location", () => {
|
||||
it('should work',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp, new ViewMetadata({
|
||||
template: '<div><location #loc></location></div>',
|
||||
directives: [Location]
|
||||
@@ -228,7 +230,7 @@ export function main() {
|
||||
|
||||
it('should return a disposable component ref',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp, new ViewMetadata({
|
||||
template: '<div><location #loc></location></div>',
|
||||
directives: [Location]
|
||||
@@ -262,7 +264,7 @@ export function main() {
|
||||
|
||||
it('should update host properties',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp, new ViewMetadata({
|
||||
template: '<div><location #loc></location></div>',
|
||||
directives: [Location]
|
||||
@@ -288,7 +290,7 @@ export function main() {
|
||||
|
||||
it('should allow to pass projectable nodes',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader, tcb: TestComponentBuilder, async) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async) => {
|
||||
tcb.overrideView(MyComp, new ViewMetadata({template: '', directives: [Location]}))
|
||||
.createAsync(MyComp)
|
||||
.then((tc) => {
|
||||
@@ -309,7 +311,8 @@ export function main() {
|
||||
describe('loadAsRoot', () => {
|
||||
it('should allow to create, update and destroy components',
|
||||
inject([AsyncTestCompleter, DynamicComponentLoader, DOCUMENT, Injector],
|
||||
(async, loader, doc, injector) => {
|
||||
(async: AsyncTestCompleter, loader: DynamicComponentLoader, doc,
|
||||
injector: Injector) => {
|
||||
var rootEl = createRootElement(doc, 'child-cmp');
|
||||
DOM.appendChild(doc.body, rootEl);
|
||||
loader.loadAsRoot(ChildComp, null, injector)
|
||||
@@ -338,7 +341,8 @@ export function main() {
|
||||
|
||||
it('should allow to pass projectable nodes',
|
||||
inject([AsyncTestCompleter, DynamicComponentLoader, DOCUMENT, Injector],
|
||||
(async, loader, doc, injector) => {
|
||||
(async: AsyncTestCompleter, loader: DynamicComponentLoader, doc,
|
||||
injector: Injector) => {
|
||||
var rootEl = createRootElement(doc, 'dummy');
|
||||
DOM.appendChild(doc.body, rootEl);
|
||||
loader.loadAsRoot(DynamicallyLoadedWithNgContent, null, injector, null,
|
||||
|
||||
@@ -818,7 +818,8 @@ function declareTests() {
|
||||
tcb.createAsync(MyComp).then(root => { fixture = root; });
|
||||
tick();
|
||||
|
||||
var cmp = fixture.debugElement.children[0].getLocal('cmp');
|
||||
var cmp: PushCmpWithAsyncPipe =
|
||||
fixture.debugElement.children[0].getLocal('cmp');
|
||||
fixture.detectChanges();
|
||||
expect(cmp.numberOfChecks).toEqual(1);
|
||||
|
||||
@@ -1155,7 +1156,7 @@ function declareTests() {
|
||||
.createAsync(MyComp)
|
||||
.then((fixture) => {
|
||||
var tc = fixture.debugElement.children[0].children[0];
|
||||
var dynamicVp = tc.inject(DynamicViewport);
|
||||
var dynamicVp: DynamicViewport = tc.inject(DynamicViewport);
|
||||
dynamicVp.done.then((_) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.children[0].children[1].nativeElement)
|
||||
@@ -1549,7 +1550,7 @@ function declareTests() {
|
||||
|
||||
it('should support moving embedded views around',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter, ANCHOR_ELEMENT],
|
||||
(tcb, async, anchorElement) => {
|
||||
(tcb: TestComponentBuilder, async, anchorElement) => {
|
||||
tcb.overrideView(MyComp, new ViewMetadata({
|
||||
template: '<div><div *someImpvp="ctxBoolProp">hello</div></div>',
|
||||
directives: [SomeImperativeViewport]
|
||||
@@ -1950,7 +1951,7 @@ class SimpleImperativeViewComponent {
|
||||
@Directive({selector: 'dynamic-vp'})
|
||||
@Injectable()
|
||||
class DynamicViewport {
|
||||
done;
|
||||
done: Promise<any>;
|
||||
constructor(vc: ViewContainerRef, compiler: Compiler) {
|
||||
var myService = new MyService();
|
||||
myService.greeting = 'dynamic greet';
|
||||
|
||||
@@ -286,7 +286,7 @@ export function main() {
|
||||
// important as we are removing the ng-content element during compilation,
|
||||
// which could skrew up text node indices.
|
||||
it('should support text nodes after content tags',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => {
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
|
||||
tcb.overrideView(
|
||||
MainComp,
|
||||
@@ -307,7 +307,7 @@ export function main() {
|
||||
// important as we are moving style tags around during compilation,
|
||||
// which could skrew up text node indices.
|
||||
it('should support text nodes after style tags',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => {
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
|
||||
tcb.overrideView(
|
||||
MainComp,
|
||||
|
||||
@@ -43,7 +43,7 @@ class SimpleClass {}
|
||||
|
||||
export function main() {
|
||||
describe("ViewResolver", () => {
|
||||
var resolver;
|
||||
var resolver: ViewResolver;
|
||||
|
||||
beforeEach(() => { resolver = new ViewResolver(); });
|
||||
|
||||
|
||||
@@ -566,7 +566,7 @@ function commonTests() {
|
||||
|
||||
it('should call onTurnStart and onTurnDone for promises created outside of run body',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
var promise;
|
||||
var promise: Promise<any>;
|
||||
|
||||
macroTask(() => {
|
||||
_zone.runOutsideAngular(() => {
|
||||
|
||||
@@ -674,7 +674,7 @@ function commonTests() {
|
||||
logOnTurnStart();
|
||||
logOnTurnDone();
|
||||
|
||||
var promise;
|
||||
var promise: Promise<any>;
|
||||
|
||||
macroTask(() => {
|
||||
_zone.runOutsideAngular(() => {
|
||||
|
||||
@@ -18,7 +18,7 @@ import {isBlank} from 'angular2/src/facade/lang';
|
||||
|
||||
export function main() {
|
||||
describe('MockViewResolver', () => {
|
||||
var viewResolver;
|
||||
var viewResolver: MockViewResolver;
|
||||
|
||||
beforeEach(() => { viewResolver = new MockViewResolver(); });
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import {provide, Inject, Injector, PLATFORM_INITIALIZER, APP_INITIALIZER} from '
|
||||
import {disposePlatform} from 'angular2/src/core/application_ref';
|
||||
import {ExceptionHandler} from 'angular2/src/facade/exceptions';
|
||||
import {Testability, TestabilityRegistry} from 'angular2/src/core/testability/testability';
|
||||
import {ComponentRef_} from "angular2/src/core/linker/dynamic_component_loader";
|
||||
import {ComponentRef_, ComponentRef} from "angular2/src/core/linker/dynamic_component_loader";
|
||||
|
||||
@Component({selector: 'hello-app'})
|
||||
@View({template: '{{greeting}} world!'})
|
||||
@@ -243,11 +243,11 @@ export function main() {
|
||||
|
||||
it('should register each application with the testability registry',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
var refPromise1 = bootstrap(HelloRootCmp, testProviders);
|
||||
var refPromise2 = bootstrap(HelloRootCmp2, testProviders);
|
||||
var refPromise1: Promise<ComponentRef> = bootstrap(HelloRootCmp, testProviders);
|
||||
var refPromise2: Promise<ComponentRef> = bootstrap(HelloRootCmp2, testProviders);
|
||||
|
||||
PromiseWrapper.all([refPromise1, refPromise2])
|
||||
.then((refs: ApplicationRef[]) => {
|
||||
.then((refs: ComponentRef[]) => {
|
||||
var registry = refs[0].injector.get(TestabilityRegistry);
|
||||
var testabilities =
|
||||
[refs[0].injector.get(Testability), refs[1].injector.get(Testability)];
|
||||
|
||||
@@ -430,8 +430,8 @@ function syncRoutesWithSyncChildrenWithDefaultRoutesWithoutParams() {
|
||||
}
|
||||
|
||||
function syncRoutesWithDynamicComponents() {
|
||||
var fixture;
|
||||
var tcb;
|
||||
var fixture: ComponentFixture;
|
||||
var tcb: TestComponentBuilder;
|
||||
var rtr: Router;
|
||||
|
||||
beforeEachProviders(() => TEST_ROUTER_PROVIDERS);
|
||||
|
||||
@@ -56,17 +56,18 @@ export function main() {
|
||||
|
||||
var tcb: TestComponentBuilder;
|
||||
var fixture: ComponentFixture;
|
||||
var rtr;
|
||||
var rtr: Router;
|
||||
|
||||
beforeEachProviders(() => TEST_ROUTER_PROVIDERS);
|
||||
|
||||
beforeEach(inject([TestComponentBuilder, Router], (tcBuilder, router) => {
|
||||
tcb = tcBuilder;
|
||||
rtr = router;
|
||||
cmpInstanceCount = 0;
|
||||
log = [];
|
||||
eventBus = new EventEmitter();
|
||||
}));
|
||||
beforeEach(inject([TestComponentBuilder, Router],
|
||||
(tcBuilder: TestComponentBuilder, router: Router) => {
|
||||
tcb = tcBuilder;
|
||||
rtr = router;
|
||||
cmpInstanceCount = 0;
|
||||
log = [];
|
||||
eventBus = new EventEmitter();
|
||||
}));
|
||||
|
||||
it('should call the routerOnActivate hook', inject([AsyncTestCompleter], (async) => {
|
||||
compile(tcb)
|
||||
|
||||
@@ -49,7 +49,8 @@ export function main() {
|
||||
describe('routerLink directive', function() {
|
||||
var tcb: TestComponentBuilder;
|
||||
var fixture: ComponentFixture;
|
||||
var router, location;
|
||||
var router: Router;
|
||||
var location: Location;
|
||||
|
||||
beforeEachProviders(() => [
|
||||
RouteRegistry,
|
||||
@@ -60,11 +61,12 @@ export function main() {
|
||||
provide(TEMPLATE_TRANSFORMS, {useClass: RouterLinkTransform, multi: true})
|
||||
]);
|
||||
|
||||
beforeEach(inject([TestComponentBuilder, Router, Location], (tcBuilder, rtr, loc) => {
|
||||
tcb = tcBuilder;
|
||||
router = rtr;
|
||||
location = loc;
|
||||
}));
|
||||
beforeEach(inject([TestComponentBuilder, Router, Location],
|
||||
(tcBuilder, rtr: Router, loc: Location) => {
|
||||
tcb = tcBuilder;
|
||||
router = rtr;
|
||||
location = loc;
|
||||
}));
|
||||
|
||||
function compile(template: string = "<router-outlet></router-outlet>") {
|
||||
return tcb.overrideView(MyComp, new View({
|
||||
@@ -77,7 +79,7 @@ export function main() {
|
||||
|
||||
it('should generate absolute hrefs that include the base href',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
location.setBaseHref('/my/base');
|
||||
(<SpyLocation>location).setBaseHref('/my/base');
|
||||
compile('<a href="hello" [routerLink]="[\'./User\']"></a>')
|
||||
.then((_) => router.config(
|
||||
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
|
||||
@@ -345,7 +347,7 @@ export function main() {
|
||||
|
||||
// router navigation is async.
|
||||
router.subscribe((_) => {
|
||||
expect(location.urlChanges).toEqual(['/user']);
|
||||
expect((<SpyLocation>location).urlChanges).toEqual(['/user']);
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
@@ -353,7 +355,7 @@ export function main() {
|
||||
|
||||
it('should navigate to link hrefs in presence of base href',
|
||||
inject([AsyncTestCompleter], (async) => {
|
||||
location.setBaseHref('/base');
|
||||
(<SpyLocation>location).setBaseHref('/base');
|
||||
compile('<a href="hello" [routerLink]="[\'./User\']"></a>')
|
||||
.then((_) => router.config(
|
||||
[new Route({path: '/user', component: UserCmp, name: 'User'})]))
|
||||
@@ -367,7 +369,7 @@ export function main() {
|
||||
|
||||
// router navigation is async.
|
||||
router.subscribe((_) => {
|
||||
expect(location.urlChanges).toEqual(['/base/user']);
|
||||
expect((<SpyLocation>location).urlChanges).toEqual(['/base/user']);
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
|
||||
export function main() {
|
||||
describe('RouteRegistry', () => {
|
||||
var registry;
|
||||
var registry: RouteRegistry;
|
||||
|
||||
beforeEach(() => { registry = new RouteRegistry(RootHostCmp); });
|
||||
|
||||
|
||||
@@ -30,10 +30,12 @@ import {
|
||||
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
|
||||
|
||||
import {provide} from 'angular2/core';
|
||||
import {RouterOutlet} from 'angular2/src/router/directives/router_outlet';
|
||||
|
||||
export function main() {
|
||||
describe('Router', () => {
|
||||
var router, location;
|
||||
var router: Router;
|
||||
var location: Location;
|
||||
|
||||
beforeEachProviders(() => [
|
||||
RouteRegistry,
|
||||
@@ -44,7 +46,7 @@ export function main() {
|
||||
]);
|
||||
|
||||
|
||||
beforeEach(inject([Router, Location], (rtr, loc) => {
|
||||
beforeEach(inject([Router, Location], (rtr: Router, loc: Location) => {
|
||||
router = rtr;
|
||||
location = loc;
|
||||
}));
|
||||
@@ -56,8 +58,8 @@ export function main() {
|
||||
router.config([new Route({path: '/', component: DummyComponent})])
|
||||
.then((_) => router.registerPrimaryOutlet(outlet))
|
||||
.then((_) => {
|
||||
expect(outlet.spy('activate')).toHaveBeenCalled();
|
||||
expect(location.urlChanges).toEqual([]);
|
||||
expect((<any>outlet).spy('activate')).toHaveBeenCalled();
|
||||
expect((<SpyLocation>location).urlChanges).toEqual([]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@@ -70,8 +72,8 @@ export function main() {
|
||||
.then((_) => router.config([new Route({path: '/a', component: DummyComponent})]))
|
||||
.then((_) => router.navigateByUrl('/a'))
|
||||
.then((_) => {
|
||||
expect(outlet.spy('activate')).toHaveBeenCalled();
|
||||
expect(location.urlChanges).toEqual(['/a']);
|
||||
expect((<any>outlet).spy('activate')).toHaveBeenCalled();
|
||||
expect((<SpyLocation>location).urlChanges).toEqual(['/a']);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@@ -85,8 +87,8 @@ export function main() {
|
||||
[new Route({path: '/a', component: DummyComponent, name: 'A'})]))
|
||||
.then((_) => router.navigate(['/A']))
|
||||
.then((_) => {
|
||||
expect(outlet.spy('activate')).toHaveBeenCalled();
|
||||
expect(location.urlChanges).toEqual(['/a']);
|
||||
expect((<any>outlet).spy('activate')).toHaveBeenCalled();
|
||||
expect((<SpyLocation>location).urlChanges).toEqual(['/a']);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@@ -99,8 +101,8 @@ export function main() {
|
||||
.then((_) => router.config([new Route({path: '/b', component: DummyComponent})]))
|
||||
.then((_) => router.navigateByUrl('/b', true))
|
||||
.then((_) => {
|
||||
expect(outlet.spy('activate')).toHaveBeenCalled();
|
||||
expect(location.urlChanges).toEqual([]);
|
||||
expect((<any>outlet).spy('activate')).toHaveBeenCalled();
|
||||
expect((<SpyLocation>location).urlChanges).toEqual([]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@@ -119,11 +121,11 @@ export function main() {
|
||||
]))
|
||||
.then((_) => {
|
||||
router.subscribe((_) => {
|
||||
expect(location.urlChanges).toEqual(['hash: a', 'replace: /b']);
|
||||
expect((<SpyLocation>location).urlChanges).toEqual(['hash: a', 'replace: /b']);
|
||||
async.done();
|
||||
});
|
||||
|
||||
location.simulateHashChange('a');
|
||||
(<SpyLocation>location).simulateHashChange('a');
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -135,11 +137,11 @@ export function main() {
|
||||
.then((_) => router.config([new Route({path: '/a', component: DummyComponent})]))
|
||||
.then((_) => {
|
||||
router.subscribe((_) => {
|
||||
expect(location.urlChanges).toEqual(['hash: a']);
|
||||
expect((<SpyLocation>location).urlChanges).toEqual(['hash: a']);
|
||||
async.done();
|
||||
});
|
||||
|
||||
location.simulateHashChange('a');
|
||||
(<SpyLocation>location).simulateHashChange('a');
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -149,11 +151,11 @@ export function main() {
|
||||
router.registerPrimaryOutlet(outlet)
|
||||
.then((_) => router.navigateByUrl('/a'))
|
||||
.then((_) => {
|
||||
expect(outlet.spy('activate')).not.toHaveBeenCalled();
|
||||
expect((<any>outlet).spy('activate')).not.toHaveBeenCalled();
|
||||
return router.config([new Route({path: '/a', component: DummyComponent})]);
|
||||
})
|
||||
.then((_) => {
|
||||
expect(outlet.spy('activate')).toHaveBeenCalled();
|
||||
expect((<any>outlet).spy('activate')).toHaveBeenCalled();
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@@ -193,7 +195,7 @@ export function main() {
|
||||
var instruction = router.generate(['/FirstCmp']);
|
||||
router.navigateByInstruction(instruction)
|
||||
.then((_) => {
|
||||
expect(outlet.spy('activate')).toHaveBeenCalled();
|
||||
expect((<any>outlet).spy('activate')).toHaveBeenCalled();
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@@ -310,13 +312,13 @@ class DummyComponent {}
|
||||
class DummyParentComp {
|
||||
}
|
||||
|
||||
function makeDummyOutlet() {
|
||||
function makeDummyOutlet(): RouterOutlet {
|
||||
var ref = new SpyRouterOutlet();
|
||||
ref.spy('canActivate').andCallFake((_) => PromiseWrapper.resolve(true));
|
||||
ref.spy('routerCanReuse').andCallFake((_) => PromiseWrapper.resolve(false));
|
||||
ref.spy('routerCanDeactivate').andCallFake((_) => PromiseWrapper.resolve(true));
|
||||
ref.spy('activate').andCallFake((_) => PromiseWrapper.resolve(true));
|
||||
return ref;
|
||||
return <any>ref;
|
||||
}
|
||||
|
||||
class AppCmp {}
|
||||
|
||||
Reference in New Issue
Block a user