Skip to content

Commit 450d363

Browse files
committed
test(router): add tests for router.d.ts
Closes angular#3282
1 parent 1666883 commit 450d363

File tree

9 files changed

+49
-12
lines changed

9 files changed

+49
-12
lines changed

docs/typescript-definition-package/templates/angular2/angular2.d.ts.template.html

-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,3 @@
2020
interface InjectableReference {}
2121
}
2222
{% endblock %}
23-
24-
declare module "angular2/angular2" {
25-
export = ng;
26-
}

docs/typescript-definition-package/templates/type-definition.template.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
{% endfor %}
6666
}
6767

68-
{% endfor %}
69-
70-
declare module "angular2/angular2" {
68+
declare module "{$ alias $}" {
7169
export = ng;
7270
}
71+
72+
{% endfor %}

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ gulp.task('!pre.test.typings', ['docs/typings'], function() {
761761

762762
// -----------------
763763
gulp.task('test.typings', ['!pre.test.typings'], function() {
764-
return gulp.src(['typing_spec/*.ts', 'dist/docs/typings/angular2/angular2.d.ts'])
764+
return gulp.src(['typing_spec/*.ts', 'dist/docs/typings/angular2/*.d.ts'])
765765
.pipe(tsc({target: 'ES5', module: 'commonjs',
766766
experimentalDecorators: true,
767767
noImplicitAny: true,

modules/angular2/router.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ export {HTML5LocationStrategy} from './src/router/html5_location_strategy';
1616
export {Location, appBaseHrefToken} from './src/router/location';
1717
export {Pipeline} from './src/router/pipeline';
1818
export * from './src/router/route_config_decorator';
19+
export * from './src/router/route_definition';
1920
export {OnActivate, OnDeactivate, OnReuse, CanDeactivate, CanReuse} from './src/router/interfaces';
2021
export {CanActivate} from './src/router/lifecycle_annotations';
22+
export {Instruction} from './src/router/instruction';
2123

2224
import {LocationStrategy} from './src/router/location_strategy';
2325
import {HTML5LocationStrategy} from './src/router/html5_location_strategy';

modules/angular2/src/router/lifecycle_annotations.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import {makeDecorator} from 'angular2/src/util/decorators';
77
import {CanActivate as CanActivateAnnotation} from './lifecycle_annotations_impl';
8+
import {Promise} from 'angular2/src/facade/async';
9+
import {Instruction} from 'angular2/src/router/instruction';
810

911
export {
1012
canReuse,
@@ -14,4 +16,6 @@ export {
1416
onDeactivate
1517
} from './lifecycle_annotations_impl';
1618

17-
export var CanActivate = makeDecorator(CanActivateAnnotation);
19+
export var CanActivate:
20+
(hook: (next: Instruction, prev: Instruction) => Promise<boolean>| boolean) => ClassDecorator =
21+
makeDecorator(CanActivateAnnotation);

modules/angular2/src/router/location_strategy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export class LocationStrategy {
99
pushState(ctx: any, title: string, url: string): void { throw _abstract(); }
1010
forward(): void { throw _abstract(); }
1111
back(): void { throw _abstract(); }
12-
onPopState(fn: (_) => any): void { throw _abstract(); }
12+
onPopState(fn: (_: any) => any): void { throw _abstract(); }
1313
getBaseHref(): string { throw _abstract(); }
1414
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import {RouteConfig as RouteConfigAnnotation} from './route_config_impl';
1+
import {RouteConfig as RouteConfigAnnotation, RouteDefinition} from './route_config_impl';
22
import {makeDecorator} from 'angular2/src/util/decorators';
3+
import {List} from 'angular2/src/facade/collection';
34

45
export {Route, Redirect, AsyncRoute, RouteDefinition} from './route_config_impl';
5-
export var RouteConfig = makeDecorator(RouteConfigAnnotation);
6+
export var RouteConfig: (configs: List<RouteDefinition>) => ClassDecorator =
7+
makeDecorator(RouteConfigAnnotation);

typing_spec/router_spec.dart

Whitespace-only changes.

typing_spec/router_spec.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
///<reference path="../dist/docs/typings/angular2/angular2.d.ts"/>
2+
///<reference path="../dist/docs/typings/angular2/router.d.ts"/>
3+
4+
import {Component, bootstrap, View} from 'angular2/angular2';
5+
import {RouteConfig, routerDirectives, routerInjectables} from 'angular2/router';
6+
7+
@Component({
8+
selector: 'my-app'
9+
})
10+
@View({
11+
template: '<h1>Hello</h1>',
12+
})
13+
class FooCmp {
14+
}
15+
16+
17+
@Component({
18+
selector: 'my-app'
19+
})
20+
@View({
21+
template: '<h1>Hello {{ name }}</h1><router-outlet></router-outlet>',
22+
directives: routerDirectives
23+
})
24+
@RouteConfig([
25+
{path: '/home', component: FooCmp}
26+
])
27+
class MyAppComponent {
28+
name: string;
29+
30+
constructor() { this.name = 'Alice'; }
31+
}
32+
33+
bootstrap(MyAppComponent, routerInjectables);

0 commit comments

Comments
 (0)