build: add bazel test rules for remainder of packages (#21053)

PR Close #21053
This commit is contained in:
Misko Hevery 2017-12-17 15:10:54 -08:00 committed by Igor Minar
parent cc1058f6e1
commit 3d50fd7cac
88 changed files with 912 additions and 322 deletions

View File

@ -1,6 +1,9 @@
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
exports_files(["tsconfig.json"]) exports_files([
"tsconfig.json",
"node_modules/angular/angular.js",
])
# This rule belongs in node_modules/BUILD # This rule belongs in node_modules/BUILD
# It's here as a workaround for # It's here as a workaround for

View File

@ -12,3 +12,7 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations';
TestBed.initTestEnvironment( TestBed.initTestEnvironment(
[BrowserDynamicTestingModule, NoopAnimationsModule], platformBrowserDynamicTesting()); [BrowserDynamicTestingModule, NoopAnimationsModule], platformBrowserDynamicTesting());
(window as any).isNode = false;
(window as any).isBrowser = true;
(window as any).global = window;

View File

@ -32,6 +32,9 @@ jasmineCore.boot = function() {
// 5) Patch jasmine ENV with code which understands ProxyZone. // 5) Patch jasmine ENV with code which understands ProxyZone.
import 'zone.js/dist/jasmine-patch.js'; import 'zone.js/dist/jasmine-patch.js';
(global as any).isNode = true;
(global as any).isBrowser = false;
// Init TestBed // Init TestBed
import {TestBed} from '@angular/core/testing'; import {TestBed} from '@angular/core/testing';
import {ServerTestingModule, platformServerTesting} from '@angular/platform-server/testing/src/server'; import {ServerTestingModule, platformServerTesting} from '@angular/platform-server/testing/src/server';

View File

@ -5,10 +5,12 @@ load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
ts_library( ts_library(
name = "testing", name = "testing",
testonly = 1, testonly = 1,
srcs = glob(["testing/**/*.ts"]), srcs = glob(["**/*.ts"]),
module_name = "@angular/common/http/testing", module_name = "@angular/common/http/testing",
tsconfig = "//packages:tsconfig", tsconfig = "//packages:tsconfig",
deps = [ deps = [
"//packages/common/http", "//packages/common/http",
"//packages/core",
"@rxjs",
], ],
) )

View File

@ -10,14 +10,14 @@ ts_library(
), ),
tsconfig = "//packages:tsconfig", tsconfig = "//packages:tsconfig",
deps = [ deps = [
"//packages/compiler",
"//packages/common", "//packages/common",
"//packages/common/locales", "//packages/common/locales",
"//packages/compiler",
"//packages/core", "//packages/core",
"//packages/core/testing", "//packages/core/testing",
"//packages/platform-browser", "//packages/platform-browser",
"//packages/platform-browser/testing",
"//packages/platform-browser-dynamic", "//packages/platform-browser-dynamic",
"//packages/platform-browser/testing",
], ],
) )

View File

@ -0,0 +1,21 @@
package(default_visibility = ["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
ng_module(
name = "forms",
srcs = glob(
[
"*.ts",
"src/**/*.ts",
],
),
module_name = "@angular/forms",
tsconfig = "//packages:tsconfig",
deps = [
"//packages/core",
"//packages/platform-browser",
"@rxjs",
],
)

View File

@ -0,0 +1,38 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
tsconfig = "//packages:tsconfig",
deps = [
"//packages/core",
"//packages/core/testing",
"//packages/forms",
"//packages/platform-browser",
"//packages/platform-browser/testing",
"@rxjs",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
deps = [
":test_lib",
"//packages/_testing_init:node",
],
)
ts_web_test(
name = "test_web",
bootstrap = [
"//:angular_bootstrap_scripts",
],
# do not sort
deps = [
"//packages/_testing_init:browser",
":test_lib",
],
)

View File

@ -10,7 +10,7 @@ import {SimpleChange} from '@angular/core';
import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal'; import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
import {AbstractControl, CheckboxControlValueAccessor, ControlValueAccessor, DefaultValueAccessor, FormArray, FormArrayName, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormGroupName, NgControl, NgForm, NgModel, NgModelGroup, SelectControlValueAccessor, SelectMultipleControlValueAccessor, ValidationErrors, Validator, Validators} from '@angular/forms'; import {AbstractControl, CheckboxControlValueAccessor, ControlValueAccessor, DefaultValueAccessor, FormArray, FormArrayName, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormGroupName, NgControl, NgForm, NgModel, NgModelGroup, SelectControlValueAccessor, SelectMultipleControlValueAccessor, ValidationErrors, Validator, Validators} from '@angular/forms';
import {composeValidators, selectValueAccessor} from '../src/directives/shared'; import {composeValidators, selectValueAccessor} from '@angular/forms/src/directives/shared';
import {SpyNgControl, SpyValueAccessor} from './spies'; import {SpyNgControl, SpyValueAccessor} from './spies';
class DummyControlValueAccessor implements ControlValueAccessor { class DummyControlValueAccessor implements ControlValueAccessor {

View File

@ -9,8 +9,8 @@
import {fakeAsync, tick} from '@angular/core/testing'; import {fakeAsync, tick} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal'; import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors} from '@angular/forms'; import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors} from '@angular/forms';
import {Validators} from '@angular/forms/src/validators';
import {of } from 'rxjs/observable/of'; import {of } from 'rxjs/observable/of';
import {Validators} from '../src/validators';
(function() { (function() {
function asyncValidator(expected: string, timeouts = {}) { function asyncValidator(expected: string, timeouts = {}) {

View File

@ -11,7 +11,7 @@ import {fakeAsync, tick} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal'; import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
import {FormControl, FormGroup, Validators} from '@angular/forms'; import {FormControl, FormGroup, Validators} from '@angular/forms';
import {FormArray} from '../src/model'; import {FormArray} from '@angular/forms/src/model';
(function() { (function() {
function asyncValidator(expected: string, timeouts = {}) { function asyncValidator(expected: string, timeouts = {}) {

View File

@ -1070,12 +1070,12 @@ import {of } from 'rxjs/observable/of';
}); });
it('should update tree validity', () => { it('should update tree validity', () => {
form._updateTreeValidity(); (form as any)._updateTreeValidity();
expect(logger).toEqual(['one', 'two', 'nested', 'three', 'form']); expect(logger).toEqual(['one', 'two', 'nested', 'three', 'form']);
}); });
it('should not emit events when turned off', () => { it('should not emit events when turned off', () => {
form._updateTreeValidity({emitEvent: false}); (form as any)._updateTreeValidity({emitEvent: false});
expect(logger).toEqual([]); expect(logger).toEqual([]);
}); });

View File

@ -1560,6 +1560,7 @@ import {MyInput, MyInputForm} from './value_accessor_integration_spec';
})); }));
it('should not update the view when the value initially came from the view', fakeAsync(() => { it('should not update the view when the value initially came from the view', fakeAsync(() => {
if (isNode) return;
const fixture = initTest(FormControlNgModel); const fixture = initTest(FormControlNgModel);
fixture.componentInstance.control = new FormControl(''); fixture.componentInstance.control = new FormControl('');
fixture.detectChanges(); fixture.detectChanges();

View File

@ -295,7 +295,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
const form = fixture.debugElement.children[0].injector.get(NgForm); const form = fixture.debugElement.children[0].injector.get(NgForm);
const name = form.control.get('name') as FormControl; const name = form.control.get('name') as FormControl;
expect(name._updateOn).toBeUndefined(); expect((name as any)._updateOn).toBeUndefined();
expect(name.updateOn).toEqual('change'); expect(name.updateOn).toEqual('change');
})); }));
@ -309,7 +309,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
const form = fixture.debugElement.children[0].injector.get(NgForm); const form = fixture.debugElement.children[0].injector.get(NgForm);
const name = form.control.get('name') as FormControl; const name = form.control.get('name') as FormControl;
expect(name._updateOn).toEqual('blur'); expect((name as any)._updateOn).toEqual('blur');
expect(name.updateOn).toEqual('blur'); expect(name.updateOn).toEqual('blur');
})); }));
@ -555,7 +555,7 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
const form = fixture.debugElement.children[0].injector.get(NgForm); const form = fixture.debugElement.children[0].injector.get(NgForm);
const name = form.control.get('name') as FormControl; const name = form.control.get('name') as FormControl;
expect(name._updateOn).toEqual('submit'); expect((name as any)._updateOn).toEqual('submit');
expect(name.updateOn).toEqual('submit'); expect(name.updateOn).toEqual('submit');
})); }));
@ -891,12 +891,12 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
const form = fixture.debugElement.children[0].injector.get(NgForm); const form = fixture.debugElement.children[0].injector.get(NgForm);
const controlOne = form.control.get('one') !as FormControl; const controlOne = form.control.get('one') !as FormControl;
expect(controlOne._updateOn).toBeUndefined(); expect((controlOne as any)._updateOn).toBeUndefined();
expect(controlOne.updateOn) expect(controlOne.updateOn)
.toEqual('blur', 'Expected first control to inherit updateOn from parent form.'); .toEqual('blur', 'Expected first control to inherit updateOn from parent form.');
const controlTwo = form.control.get('two') !as FormControl; const controlTwo = form.control.get('two') !as FormControl;
expect(controlTwo._updateOn).toBeUndefined(); expect((controlTwo as any)._updateOn).toBeUndefined();
expect(controlTwo.updateOn) expect(controlTwo.updateOn)
.toEqual('blur', 'Expected last control to inherit updateOn from parent form.'); .toEqual('blur', 'Expected last control to inherit updateOn from parent form.');
})); }));
@ -932,12 +932,13 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
const form = fixture.debugElement.children[0].injector.get(NgForm); const form = fixture.debugElement.children[0].injector.get(NgForm);
const controlOne = form.control.get('one') !as FormControl; const controlOne = form.control.get('one') !as FormControl;
expect(controlOne._updateOn).toBeUndefined(); expect((controlOne as any)._updateOn).toBeUndefined();
expect(controlOne.updateOn) expect(controlOne.updateOn)
.toEqual('change', 'Expected control updateOn to inherit form updateOn.'); .toEqual('change', 'Expected control updateOn to inherit form updateOn.');
const controlTwo = form.control.get('two') !as FormControl; const controlTwo = form.control.get('two') !as FormControl;
expect(controlTwo._updateOn).toEqual('blur', 'Expected control to set blur override.'); expect((controlTwo as any)._updateOn)
.toEqual('blur', 'Expected control to set blur override.');
expect(controlTwo.updateOn) expect(controlTwo.updateOn)
.toEqual('blur', 'Expected control updateOn to override form updateOn.'); .toEqual('blur', 'Expected control updateOn to override form updateOn.');
})); }));

View File

@ -9,13 +9,13 @@
import {fakeAsync, tick} from '@angular/core/testing'; import {fakeAsync, tick} from '@angular/core/testing';
import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
import {AbstractControl, AsyncValidatorFn, FormArray, FormControl, Validators} from '@angular/forms'; import {AbstractControl, AsyncValidatorFn, FormArray, FormControl, Validators} from '@angular/forms';
import {normalizeAsyncValidator} from '@angular/forms/src/directives/normalize_validator';
import {AsyncValidator, ValidationErrors, ValidatorFn} from '@angular/forms/src/directives/validators';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {of } from 'rxjs/observable/of'; import {of } from 'rxjs/observable/of';
import {timer} from 'rxjs/observable/timer'; import {timer} from 'rxjs/observable/timer';
import {first} from 'rxjs/operator/first'; import {first} from 'rxjs/operator/first';
import {map} from 'rxjs/operator/map'; import {map} from 'rxjs/operator/map';
import {normalizeAsyncValidator} from '../src/directives/normalize_validator';
import {AsyncValidator, ValidationErrors, ValidatorFn} from '../src/directives/validators';
(function() { (function() {
function validator(key: string, error: any): ValidatorFn { function validator(key: string, error: any): ValidatorFn {

View File

@ -164,6 +164,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
describe('in reactive forms', () => { describe('in reactive forms', () => {
it(`should support primitive values`, () => { it(`should support primitive values`, () => {
if (isNode) return;
const fixture = initTest(FormControlNameSelect); const fixture = initTest(FormControlNameSelect);
fixture.detectChanges(); fixture.detectChanges();
@ -183,6 +184,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
}); });
it(`should support objects`, () => { it(`should support objects`, () => {
if (isNode) return;
const fixture = initTest(FormControlSelectNgValue); const fixture = initTest(FormControlSelectNgValue);
fixture.detectChanges(); fixture.detectChanges();
@ -201,6 +203,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
}); });
it('should compare options using provided compareWith function', () => { it('should compare options using provided compareWith function', () => {
if (isNode) return;
const fixture = initTest(FormControlSelectWithCompareFn); const fixture = initTest(FormControlSelectWithCompareFn);
fixture.detectChanges(); fixture.detectChanges();
@ -211,6 +214,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
}); });
it('should support re-assigning the options array with compareWith', () => { it('should support re-assigning the options array with compareWith', () => {
if (isNode) return;
const fixture = initTest(FormControlSelectWithCompareFn); const fixture = initTest(FormControlSelectWithCompareFn);
fixture.detectChanges(); fixture.detectChanges();
@ -239,6 +243,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
describe('in template-driven forms', () => { describe('in template-driven forms', () => {
it('with option values that are objects', fakeAsync(() => { it('with option values that are objects', fakeAsync(() => {
if (isNode) return;
const fixture = initTest(NgModelSelectForm); const fixture = initTest(NgModelSelectForm);
const comp = fixture.componentInstance; const comp = fixture.componentInstance;
comp.cities = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'Buffalo'}]; comp.cities = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'Buffalo'}];
@ -263,6 +268,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
})); }));
it('when new options are added', fakeAsync(() => { it('when new options are added', fakeAsync(() => {
if (isNode) return;
const fixture = initTest(NgModelSelectForm); const fixture = initTest(NgModelSelectForm);
const comp = fixture.componentInstance; const comp = fixture.componentInstance;
comp.cities = [{'name': 'SF'}, {'name': 'NYC'}]; comp.cities = [{'name': 'SF'}, {'name': 'NYC'}];
@ -300,6 +306,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
})); }));
it('when option values have same content, but different identities', fakeAsync(() => { it('when option values have same content, but different identities', fakeAsync(() => {
if (isNode) return;
const fixture = initTest(NgModelSelectForm); const fixture = initTest(NgModelSelectForm);
const comp = fixture.componentInstance; const comp = fixture.componentInstance;
comp.cities = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'NYC'}]; comp.cities = [{'name': 'SF'}, {'name': 'NYC'}, {'name': 'NYC'}];
@ -347,6 +354,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
}); });
it('should compare options using provided compareWith function', fakeAsync(() => { it('should compare options using provided compareWith function', fakeAsync(() => {
if (isNode) return;
const fixture = initTest(NgModelSelectWithCustomCompareFnForm); const fixture = initTest(NgModelSelectWithCustomCompareFnForm);
const comp = fixture.componentInstance; const comp = fixture.componentInstance;
comp.selectedCity = {id: 1, name: 'SF'}; comp.selectedCity = {id: 1, name: 'SF'};
@ -361,6 +369,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
})); }));
it('should support re-assigning the options array with compareWith', fakeAsync(() => { it('should support re-assigning the options array with compareWith', fakeAsync(() => {
if (isNode) return;
const fixture = initTest(NgModelSelectWithCustomCompareFnForm); const fixture = initTest(NgModelSelectWithCustomCompareFnForm);
fixture.componentInstance.selectedCity = {id: 1, name: 'SF'}; fixture.componentInstance.selectedCity = {id: 1, name: 'SF'};
fixture.componentInstance.cities = [{id: 1, name: 'SF'}, {id: 2, name: 'NY'}]; fixture.componentInstance.cities = [{id: 1, name: 'SF'}, {id: 2, name: 'NY'}];
@ -400,6 +409,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
describe('in reactive forms', () => { describe('in reactive forms', () => {
it('should support primitive values', () => { it('should support primitive values', () => {
if (isNode) return;
const fixture = initTest(FormControlSelectMultiple); const fixture = initTest(FormControlSelectMultiple);
fixture.detectChanges(); fixture.detectChanges();
@ -410,6 +420,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
}); });
it('should support objects', () => { it('should support objects', () => {
if (isNode) return;
const fixture = initTest(FormControlSelectMultipleNgValue); const fixture = initTest(FormControlSelectMultipleNgValue);
fixture.detectChanges(); fixture.detectChanges();
@ -427,6 +438,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
}); });
it('should compare options using provided compareWith function', fakeAsync(() => { it('should compare options using provided compareWith function', fakeAsync(() => {
if (isNode) return;
const fixture = initTest(FormControlSelectMultipleWithCompareFn); const fixture = initTest(FormControlSelectMultipleWithCompareFn);
fixture.detectChanges(); fixture.detectChanges();
tick(); tick();
@ -478,6 +490,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
it('should reflect state of model after option selected and new options subsequently added', it('should reflect state of model after option selected and new options subsequently added',
fakeAsync(() => { fakeAsync(() => {
if (isNode) return;
setSelectedCities([]); setSelectedCities([]);
selectOptionViaUI('1: Object'); selectOptionViaUI('1: Object');
@ -491,6 +504,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
it('should reflect state of model after option selected and then other options removed', it('should reflect state of model after option selected and then other options removed',
fakeAsync(() => { fakeAsync(() => {
if (isNode) return;
setSelectedCities([]); setSelectedCities([]);
selectOptionViaUI('1: Object'); selectOptionViaUI('1: Object');
@ -512,6 +526,7 @@ import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'
}); });
it('should compare options using provided compareWith function', fakeAsync(() => { it('should compare options using provided compareWith function', fakeAsync(() => {
if (isNode) return;
const fixture = initTest(NgModelSelectMultipleWithCustomCompareFnForm); const fixture = initTest(NgModelSelectMultipleWithCustomCompareFnForm);
const comp = fixture.componentInstance; const comp = fixture.componentInstance;
comp.cities = [{id: 1, name: 'SF'}, {id: 2, name: 'LA'}]; comp.cities = [{id: 1, name: 'SF'}, {id: 2, name: 'LA'}];

View File

@ -0,0 +1,39 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
tsconfig = "//packages:tsconfig",
deps = [
"//packages/core",
"//packages/core/testing",
"//packages/http",
"//packages/http/testing",
"//packages/platform-browser",
"//packages/platform-browser/testing",
"@rxjs",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
deps = [
":test_lib",
"//packages/_testing_init:node",
],
)
ts_web_test(
name = "test_web",
bootstrap = [
"//:angular_bootstrap_scripts",
],
# do not sort
deps = [
"//packages/_testing_init:browser",
":test_lib",
],
)

View File

@ -8,13 +8,14 @@
import {Injector} from '@angular/core'; import {Injector} from '@angular/core';
import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal'; import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
import {BrowserJsonp} from '@angular/http/src/backends/browser_jsonp';
import {JSONPBackend, JSONPConnection} from '@angular/http/src/backends/jsonp_backend';
import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options';
import {BaseResponseOptions, ResponseOptions} from '@angular/http/src/base_response_options';
import {ReadyState, RequestMethod, ResponseType} from '@angular/http/src/enums';
import {Request} from '@angular/http/src/static_request';
import {Response} from '@angular/http/src/static_response';
import {expect} from '@angular/platform-browser/testing/src/matchers'; import {expect} from '@angular/platform-browser/testing/src/matchers';
import {BrowserJsonp} from '../../src/backends/browser_jsonp';
import {JSONPBackend, JSONPConnection} from '../../src/backends/jsonp_backend';
import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options';
import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options';
import {ReadyState, RequestMethod, ResponseType} from '../../src/enums';
import {Request} from '../../src/static_request';
let existingScripts: MockBrowserJsonp[] = []; let existingScripts: MockBrowserJsonp[] = [];
@ -75,10 +76,10 @@ class MockBrowserJsonp extends BrowserJsonp {
describe('JSONPConnection', () => { describe('JSONPConnection', () => {
it('should use the injected BaseResponseOptions to create the response', it('should use the injected BaseResponseOptions to create the response',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const connection = new JSONPConnection( const connection = new (JSONPConnection as any)(
sampleRequest, new MockBrowserJsonp(), sampleRequest, new MockBrowserJsonp(),
new ResponseOptions({type: ResponseType.Error})); new ResponseOptions({type: ResponseType.Error}));
connection.response.subscribe(res => { connection.response.subscribe((res: Response) => {
expect(res.type).toBe(ResponseType.Error); expect(res.type).toBe(ResponseType.Error);
async.done(); async.done();
}); });
@ -88,7 +89,7 @@ class MockBrowserJsonp extends BrowserJsonp {
it('should ignore load/callback when disposed', it('should ignore load/callback when disposed',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp()); const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp());
const spy = new SpyObject(); const spy = new SpyObject();
const loadSpy = spy.spy('load'); const loadSpy = spy.spy('load');
const errorSpy = spy.spy('error'); const errorSpy = spy.spy('error');
@ -111,13 +112,13 @@ class MockBrowserJsonp extends BrowserJsonp {
it('should report error if loaded without invoking callback', it('should report error if loaded without invoking callback',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp()); const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp());
connection.response.subscribe( connection.response.subscribe(
res => { (res: Response) => {
expect('response listener called').toBe(false); expect('response listener called').toBe(false);
async.done(); async.done();
}, },
err => { (err: Response) => {
expect(err.text()).toEqual('JSONP injected script did not invoke callback.'); expect(err.text()).toEqual('JSONP injected script did not invoke callback.');
async.done(); async.done();
}); });
@ -127,14 +128,14 @@ class MockBrowserJsonp extends BrowserJsonp {
it('should report error if script contains error', it('should report error if script contains error',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp()); const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp());
connection.response.subscribe( connection.response.subscribe(
res => { (res: Response) => {
expect('response listener called').toBe(false); expect('response listener called').toBe(false);
async.done(); async.done();
}, },
err => { (err: Response) => {
expect(err.text()).toBe('Oops!'); expect(err.text()).toBe('Oops!');
async.done(); async.done();
}); });
@ -149,16 +150,18 @@ class MockBrowserJsonp extends BrowserJsonp {
const base = new BaseRequestOptions(); const base = new BaseRequestOptions();
const req = new Request(base.merge( const req = new Request(base.merge(
new RequestOptions({url: 'https://google.com', method: method})) as any); new RequestOptions({url: 'https://google.com', method: method})) as any);
expect(() => new JSONPConnection(req, new MockBrowserJsonp()).response.subscribe()) expect(
() => new (JSONPConnection as any)(req, new MockBrowserJsonp())
.response.subscribe())
.toThrowError(); .toThrowError();
}); });
}); });
it('should respond with data passed to callback', it('should respond with data passed to callback',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp()); const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp());
connection.response.subscribe(res => { connection.response.subscribe((res: Response) => {
expect(res.json()).toEqual(({fake_payload: true, blob_id: 12345})); expect(res.json()).toEqual(({fake_payload: true, blob_id: 12345}));
async.done(); async.done();
}); });

View File

@ -8,15 +8,14 @@
import {Injector} from '@angular/core'; import {Injector} from '@angular/core';
import {AsyncTestCompleter, beforeEach, describe, inject, it, xit} from '@angular/core/testing/src/testing_internal'; import {AsyncTestCompleter, beforeEach, describe, inject, it, xit} from '@angular/core/testing/src/testing_internal';
import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options';
import {BaseResponseOptions, ResponseOptions} from '@angular/http/src/base_response_options';
import {Request} from '@angular/http/src/static_request';
import {Response} from '@angular/http/src/static_response';
import {MockBackend, MockConnection} from '@angular/http/testing/src/mock_backend';
import {expect} from '@angular/platform-browser/testing/src/matchers'; import {expect} from '@angular/platform-browser/testing/src/matchers';
import {ReplaySubject} from 'rxjs/ReplaySubject'; import {ReplaySubject} from 'rxjs/ReplaySubject';
import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options';
import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options';
import {Request} from '../../src/static_request';
import {Response} from '../../src/static_response';
import {MockBackend, MockConnection} from '../../testing/src/mock_backend';
{ {
describe('MockBackend', () => { describe('MockBackend', () => {

View File

@ -8,17 +8,17 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, beforeEachProviders, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal'; import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, beforeEachProviders, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
import {BrowserXhr} from '@angular/http/src/backends/browser_xhr';
import {CookieXSRFStrategy, XHRBackend, XHRConnection} from '@angular/http/src/backends/xhr_backend';
import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options';
import {BaseResponseOptions, ResponseOptions} from '@angular/http/src/base_response_options';
import {ResponseContentType, ResponseType} from '@angular/http/src/enums';
import {Headers} from '@angular/http/src/headers';
import {XSRFStrategy} from '@angular/http/src/interfaces';
import {Request} from '@angular/http/src/static_request';
import {Response} from '@angular/http/src/static_response';
import {URLSearchParams} from '@angular/http/src/url_search_params';
import {ɵgetDOM as getDOM} from '@angular/platform-browser'; import {ɵgetDOM as getDOM} from '@angular/platform-browser';
import {BrowserXhr} from '../../src/backends/browser_xhr';
import {CookieXSRFStrategy, XHRBackend, XHRConnection} from '../../src/backends/xhr_backend';
import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options';
import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options';
import {ResponseContentType, ResponseType} from '../../src/enums';
import {Headers} from '../../src/headers';
import {XSRFStrategy} from '../../src/interfaces';
import {Request} from '../../src/static_request';
import {Response} from '../../src/static_response';
import {URLSearchParams} from '../../src/url_search_params';
let abortSpy: any; let abortSpy: any;
let sendSpy: any; let sendSpy: any;
@ -422,7 +422,7 @@ class MockBrowserXHR extends BrowserXhr {
(res: Response) => { (res: Response) => {
}, },
errRes => { (errRes: Response) => {
expect(errRes.status).toBe(statusCode); expect(errRes.status).toBe(statusCode);
async.done(); async.done();
}); });
@ -444,7 +444,7 @@ class MockBrowserXHR extends BrowserXhr {
nextCalled = true; nextCalled = true;
expect(res.status).toBe(statusCode); expect(res.status).toBe(statusCode);
}, },
errRes => { errorCalled = true; }, (errRes: Response) => { errorCalled = true; },
() => { () => {
expect(nextCalled).toBe(true); expect(nextCalled).toBe(true);
expect(errorCalled).toBe(false); expect(errorCalled).toBe(false);
@ -461,7 +461,7 @@ class MockBrowserXHR extends BrowserXhr {
const connection = new XHRConnection( const connection = new XHRConnection(
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode})); sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
connection.response.subscribe(res => { connection.response.subscribe((res: Response) => {
expect(res.ok).toBe(true); expect(res.ok).toBe(true);
async.done(); async.done();
}); });
@ -477,8 +477,8 @@ class MockBrowserXHR extends BrowserXhr {
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode})); sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
connection.response.subscribe( connection.response.subscribe(
res => { throw 'should not be called'; }, (res: Response) => { throw 'should not be called'; },
errRes => { (errRes: Response) => {
expect(errRes.ok).toBe(false); expect(errRes.ok).toBe(false);
async.done(); async.done();
}); });
@ -497,7 +497,7 @@ class MockBrowserXHR extends BrowserXhr {
connection.response.subscribe( connection.response.subscribe(
(res: Response) => { nextCalled = true; }, (res: Response) => { nextCalled = true; },
errRes => { (errRes: Response) => {
expect(errRes.status).toBe(statusCode); expect(errRes.status).toBe(statusCode);
expect(nextCalled).toBe(false); expect(nextCalled).toBe(false);
async.done(); async.done();
@ -553,8 +553,8 @@ class MockBrowserXHR extends BrowserXhr {
connection1.response.subscribe((res: Response) => { connection1.response.subscribe((res: Response) => {
expect(res.text()).toBe(responseBody); expect(res.text()).toBe(responseBody);
connection2.response.subscribe(ress => { connection2.response.subscribe((res: Response) => {
expect(ress.text()).toBe(responseBody); expect(res.text()).toBe(responseBody);
async.done(); async.done();
}); });
existingXHRs[1].setStatusCode(200); existingXHRs[1].setStatusCode(200);

View File

@ -7,9 +7,9 @@
*/ */
import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
import {BaseRequestOptions, RequestOptions} from '../src/base_request_options'; import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options';
import {RequestMethod} from '../src/enums'; import {RequestMethod} from '@angular/http/src/enums';
import {Headers} from '../src/headers'; import {Headers} from '@angular/http/src/headers';
{ {
describe('BaseRequestOptions', () => { describe('BaseRequestOptions', () => {

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Headers} from '../src/headers'; import {Headers} from '@angular/http/src/headers';
{ {
describe('Headers', () => { describe('Headers', () => {

View File

@ -9,12 +9,12 @@
import {Injector} from '@angular/core'; import {Injector} from '@angular/core';
import {TestBed, getTestBed} from '@angular/core/testing'; import {TestBed, getTestBed} from '@angular/core/testing';
import {AsyncTestCompleter, afterEach, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal'; import {AsyncTestCompleter, afterEach, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
import {stringToArrayBuffer} from '@angular/http/src/http_utils';
import {expect} from '@angular/platform-browser/testing/src/matchers'; import {expect} from '@angular/platform-browser/testing/src/matchers';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {zip} from 'rxjs/observable/zip'; import {zip} from 'rxjs/observable/zip';
import {BaseRequestOptions, ConnectionBackend, Http, HttpModule, JSONPBackend, Jsonp, JsonpModule, Request, RequestMethod, RequestOptions, Response, ResponseContentType, ResponseOptions, URLSearchParams, XHRBackend} from '../index'; import {BaseRequestOptions, ConnectionBackend, Http, HttpModule, JSONPBackend, Jsonp, JsonpModule, Request, RequestMethod, RequestOptions, Response, ResponseContentType, ResponseOptions, URLSearchParams, XHRBackend} from '../index';
import {stringToArrayBuffer} from '../src/http_utils';
import {MockBackend, MockConnection} from '../testing/src/mock_backend'; import {MockBackend, MockConnection} from '../testing/src/mock_backend';
{ {

View File

@ -7,14 +7,13 @@
*/ */
import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
import {RequestOptions} from '@angular/http/src/base_request_options';
import {ContentType} from '@angular/http/src/enums';
import {Headers} from '@angular/http/src/headers';
import {stringToArrayBuffer, stringToArrayBuffer8} from '@angular/http/src/http_utils';
import {ArrayBuffer, Request} from '@angular/http/src/static_request';
import {ɵgetDOM as getDOM} from '@angular/platform-browser'; import {ɵgetDOM as getDOM} from '@angular/platform-browser';
import {RequestOptions} from '../src/base_request_options';
import {ContentType} from '../src/enums';
import {Headers} from '../src/headers';
import {stringToArrayBuffer, stringToArrayBuffer8} from '../src/http_utils';
import {ArrayBuffer, Request} from '../src/static_request';
{ {
describe('Request', () => { describe('Request', () => {
describe('detectContentType', () => { describe('detectContentType', () => {

View File

@ -8,8 +8,8 @@
import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
import {ResponseOptions} from '../src/base_response_options'; import {ResponseOptions} from '@angular/http/src/base_response_options';
import {Response} from '../src/static_response'; import {Response} from '@angular/http/src/static_response';

View File

@ -7,7 +7,7 @@
*/ */
import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
import {URLSearchParams} from '../src/url_search_params'; import {URLSearchParams} from '@angular/http/src/url_search_params';
{ {
describe('URLSearchParams', () => { describe('URLSearchParams', () => {

View File

@ -0,0 +1,21 @@
package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
ts_library(
name = "language-service",
srcs = glob(
[
"*.ts",
"src/**/*.ts",
],
),
module_name = "@angular/language-service",
tsconfig = "//packages:tsconfig",
deps = [
"//packages:types",
"//packages/compiler",
"//packages/compiler-cli",
"//packages/core",
],
)

View File

@ -72,7 +72,7 @@ export class ReflectorHost implements StaticSymbolResolverHost {
containingFile = path.join(this.options.basePath !, 'index.ts'); containingFile = path.join(this.options.basePath !, 'index.ts');
} }
const resolved = const resolved =
ts.resolveModuleName(moduleName, containingFile, this.options, this.hostAdapter) ts.resolveModuleName(moduleName, containingFile !, this.options, this.hostAdapter)
.resolvedModule; .resolvedModule;
return resolved ? resolved.resolvedFileName : null; return resolved ? resolved.resolvedFileName : null;
} }

View File

@ -0,0 +1,25 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
tsconfig = "//packages:tsconfig",
deps = [
"//packages:types",
"//packages/compiler",
"//packages/language-service",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
# dissable since tests are running but not yet passing
tags = ["manual"],
deps = [
":test_lib",
"//packages/_testing_init:node",
],
)

View File

@ -0,0 +1,43 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
tsconfig = "//packages:tsconfig",
deps = [
"//packages:types",
"//packages/compiler",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser-dynamic",
"//packages/platform-browser-dynamic/testing",
"//packages/platform-browser/testing",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
# dissable since tests are running but not yet passing
tags = ["manual"],
deps = [
":test_lib",
"//packages/_testing_init:node",
],
)
ts_web_test(
name = "test_web",
bootstrap = [
"//:angular_bootstrap_scripts",
],
# dissable since tests are running but not yet passing
tags = ["manual"],
# do not sort
deps = [
"//packages/_testing_init:browser",
":test_lib",
],
)

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {MetadataOverrider} from '@angular/platform-browser-dynamic/testing/src/metadata_overrider';
import {expect} from '@angular/platform-browser/testing/src/matchers'; import {expect} from '@angular/platform-browser/testing/src/matchers';
import {MetadataOverrider} from '../testing/src/metadata_overrider';
interface SomeMetadataType { interface SomeMetadataType {
plainProp?: string; plainProp?: string;

View File

@ -0,0 +1,49 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
tsconfig = "//packages:tsconfig",
deps = [
"//packages:types",
"//packages/animations",
"//packages/animations/browser",
"//packages/animations/browser/testing",
"//packages/common",
"//packages/compiler",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
"//packages/platform-browser/animations",
"//packages/platform-browser/testing",
"@rxjs",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
# dissable since tests are running but not yet passing
tags = ["manual"],
deps = [
":test_lib",
"//packages/_testing_init:node",
],
)
ts_web_test(
name = "test_web",
bootstrap = [
"//:angular_bootstrap_scripts",
],
# dissable since tests are running but not yet passing
tags = ["manual"],
# do not sort
deps = [
"//packages/_testing_init:browser",
":test_lib",
],
)

View File

@ -161,7 +161,7 @@ function bootstrap(
inject([AsyncTestCompleter], (done: AsyncTestCompleter) => { inject([AsyncTestCompleter], (done: AsyncTestCompleter) => {
const logger = new MockConsole(); const logger = new MockConsole();
const errorHandler = new ErrorHandler(); const errorHandler = new ErrorHandler();
errorHandler._console = logger as any; (errorHandler as any)._console = logger as any;
expect( expect(
() => bootstrap( () => bootstrap(
HelloRootDirectiveIsNotCmp, [{provide: ErrorHandler, useValue: errorHandler}])) HelloRootDirectiveIsNotCmp, [{provide: ErrorHandler, useValue: errorHandler}]))
@ -173,7 +173,7 @@ function bootstrap(
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const logger = new MockConsole(); const logger = new MockConsole();
const errorHandler = new ErrorHandler(); const errorHandler = new ErrorHandler();
errorHandler._console = logger as any; (errorHandler as any)._console = logger as any;
bootstrap(NonExistentComp, [ bootstrap(NonExistentComp, [
{provide: ErrorHandler, useValue: errorHandler} {provide: ErrorHandler, useValue: errorHandler}
]).then(null, (reason) => { ]).then(null, (reason) => {
@ -187,7 +187,7 @@ function bootstrap(
it('should throw if no provider', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { it('should throw if no provider', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const logger = new MockConsole(); const logger = new MockConsole();
const errorHandler = new ErrorHandler(); const errorHandler = new ErrorHandler();
errorHandler._console = logger as any; (errorHandler as any)._console = logger as any;
class IDontExist {} class IDontExist {}
@ -223,7 +223,7 @@ function bootstrap(
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const logger = new MockConsole(); const logger = new MockConsole();
const errorHandler = new ErrorHandler(); const errorHandler = new ErrorHandler();
errorHandler._console = logger as any; (errorHandler as any)._console = logger as any;
const refPromise = const refPromise =
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]); bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
@ -238,7 +238,7 @@ function bootstrap(
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const logger = new MockConsole(); const logger = new MockConsole();
const errorHandler = new ErrorHandler(); const errorHandler = new ErrorHandler();
errorHandler._console = logger as any; (errorHandler as any)._console = logger as any;
const refPromise = const refPromise =
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]); bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);

View File

@ -0,0 +1,33 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
tsconfig = "//packages:tsconfig",
deps = [
"//packages:types",
"//packages/animations",
"//packages/common",
"//packages/common/http",
"//packages/common/http/testing",
"//packages/compiler",
"//packages/core",
"//packages/core/testing",
"//packages/http",
"//packages/http/testing",
"//packages/platform-browser",
"//packages/platform-server",
"@rxjs",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
deps = [
":test_lib",
"//packages/_testing_init:node",
],
)

View File

@ -0,0 +1,23 @@
package(default_visibility = ["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
ts_library(
name = "platform-webworker-dynamic",
srcs = glob(
[
"*.ts",
"src/**/*.ts",
],
),
module_name = "@angular/platform-webworker-dynamic",
tsconfig = "//packages:tsconfig",
deps = [
"//packages:types",
"//packages/common",
"//packages/compiler",
"//packages/core",
"//packages/platform-browser-dynamic",
],
)

View File

@ -0,0 +1,23 @@
package(default_visibility = ["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
ts_library(
name = "platform-webworker",
srcs = glob(
[
"*.ts",
"src/**/*.ts",
],
),
module_name = "@angular/platform-webworker",
tsconfig = "//packages:tsconfig",
deps = [
"//packages:types",
"//packages/common",
"//packages/compiler",
"//packages/core",
"//packages/platform-browser",
],
)

View File

@ -0,0 +1,20 @@
package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
ts_library(
name = "testing",
testonly = 1,
srcs = glob(["**/*.ts"]),
module_name = "@angular/platform-browser-dynamic/testing",
tsconfig = "//packages:tsconfig",
deps = [
"//packages/compiler",
"//packages/compiler/testing",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
"//packages/platform-browser/testing",
],
)

View File

@ -0,0 +1,41 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
tsconfig = "//packages:tsconfig",
deps = [
"//packages:types",
"//packages/compiler",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
"//packages/platform-browser-dynamic/testing",
"//packages/platform-browser/testing",
"//packages/platform-webworker",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
deps = [
":test_lib",
"//packages/_testing_init:node",
],
)
ts_web_test(
name = "test_web",
bootstrap = [
"//:angular_bootstrap_scripts",
],
# do not sort
deps = [
"//packages/_testing_init:browser",
":test_lib",
],
)

View File

@ -34,9 +34,10 @@ import {createPairedMessageBuses} from './web_worker_test_util';
}); });
it('should call registered method with correct arguments', it('should call registered method with correct arguments',
inject([Serializer], (serializer: Serializer) => { inject([Serializer], (serializer: Serializer) => {
const broker = new ServiceMessageBroker(messageBuses.ui, serializer, CHANNEL); const broker = new (ServiceMessageBroker as any)(messageBuses.ui, serializer, CHANNEL);
broker.registerMethod( broker.registerMethod(
TEST_METHOD, [SerializerTypes.PRIMITIVE, SerializerTypes.PRIMITIVE], (arg1, arg2) => { TEST_METHOD, [SerializerTypes.PRIMITIVE, SerializerTypes.PRIMITIVE],
(arg1: any, arg2: any) => {
expect(arg1).toEqual(PASSED_ARG_1); expect(arg1).toEqual(PASSED_ARG_1);
expect(arg2).toEqual(PASSED_ARG_2); expect(arg2).toEqual(PASSED_ARG_2);
}); });
@ -47,8 +48,8 @@ import {createPairedMessageBuses} from './web_worker_test_util';
})); }));
it('should return promises to the worker', inject([Serializer], (serializer: Serializer) => { it('should return promises to the worker', inject([Serializer], (serializer: Serializer) => {
const broker = new ServiceMessageBroker(messageBuses.ui, serializer, CHANNEL); const broker = new (ServiceMessageBroker as any)(messageBuses.ui, serializer, CHANNEL);
broker.registerMethod(TEST_METHOD, [SerializerTypes.PRIMITIVE], (arg1) => { broker.registerMethod(TEST_METHOD, [SerializerTypes.PRIMITIVE], (arg1: any) => {
expect(arg1).toEqual(PASSED_ARG_1); expect(arg1).toEqual(PASSED_ARG_1);
return new Promise((res, rej) => { return new Promise((res, rej) => {
try { try {

View File

@ -130,7 +130,9 @@ export class MockMessageBus extends MessageBus {
attachToZone(zone: NgZone) {} attachToZone(zone: NgZone) {}
} }
export class MockMessageBrokerFactory extends ClientMessageBrokerFactory { export const _ClientMessageBrokerFactory: {new (a: any, b: any): ClientMessageBrokerFactory} =
ClientMessageBrokerFactory;
export class MockMessageBrokerFactory extends _ClientMessageBrokerFactory {
constructor(private _messageBroker: ClientMessageBroker) { super(null !, null !); } constructor(private _messageBroker: ClientMessageBroker) { super(null !, null !); }
createMessageBroker(channel: string, runInZone = true) { return this._messageBroker; } createMessageBroker(channel: string, runInZone = true) { return this._messageBroker; }
} }

View File

@ -67,18 +67,18 @@ import {SpyMessageBroker} from './spies';
it('should get location on init', () => { it('should get location on init', () => {
const platformLocation = createWebWorkerPlatformLocation(null !); const platformLocation = createWebWorkerPlatformLocation(null !);
expectBrokerCall(broker, 'getLocation'); expectBrokerCall(broker, 'getLocation');
platformLocation.init(); (platformLocation as any).init();
}); });
it('should throw if set pathname is called before init finishes', () => { it('should throw if set pathname is called before init finishes', () => {
const platformLocation = createWebWorkerPlatformLocation(null !); const platformLocation = createWebWorkerPlatformLocation(null !);
platformLocation.init(); (platformLocation as any).init();
expect(() => platformLocation.pathname = 'TEST').toThrowError(); expect(() => platformLocation.pathname = 'TEST').toThrowError();
}); });
it('should send pathname to render thread', done => { it('should send pathname to render thread', done => {
const platformLocation = createWebWorkerPlatformLocation(TEST_LOCATION); const platformLocation = createWebWorkerPlatformLocation(TEST_LOCATION);
platformLocation.init().then((_) => { (platformLocation as any).init().then((_: any) => {
const PATHNAME = '/test'; const PATHNAME = '/test';
expectBrokerCall(broker, 'setPathname', [PATHNAME]); expectBrokerCall(broker, 'setPathname', [PATHNAME]);
platformLocation.pathname = PATHNAME; platformLocation.pathname = PATHNAME;

View File

@ -184,10 +184,10 @@ function createWebWorkerBrokerFactory(
const wwMessageBus = messageBuses.worker; const wwMessageBus = messageBuses.worker;
// set up the worker side // set up the worker side
const wwBrokerFactory = new ClientMessageBrokerFactory(wwMessageBus, wwSerializer); const wwBrokerFactory = new (ClientMessageBrokerFactory as any)(wwMessageBus, wwSerializer);
// set up the ui side // set up the ui side
const uiBrokerFactory = new ServiceMessageBrokerFactory(uiMessageBus, uiSerializer); const uiBrokerFactory = new (ServiceMessageBrokerFactory as any)(uiMessageBus, uiSerializer);
const renderer = new MessageBasedRenderer2( const renderer = new MessageBasedRenderer2(
uiBrokerFactory, uiMessageBus, uiSerializer, uiRenderStore, domRendererFactory); uiBrokerFactory, uiMessageBus, uiSerializer, uiRenderStore, domRendererFactory);
renderer.start(); renderer.start();

View File

@ -12,6 +12,9 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
__karma__.loaded = function() {}; __karma__.loaded = function() {};
window.isNode = false;
window.isBrowser = true;
function isJsFile(path) { function isJsFile(path) {
return path.slice(-3) == '.js'; return path.slice(-3) == '.js';
} }

View File

@ -0,0 +1,46 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
tsconfig = "//packages:tsconfig",
deps = [
"//packages/common",
"//packages/common/testing",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
"//packages/platform-browser/testing",
"//packages/router",
"//packages/router/testing",
"@rxjs",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
# dissable since tests are running but not yet passing
tags = ["manual"],
deps = [
":test_lib",
"//packages/_testing_init:node",
],
)
ts_web_test(
name = "test_web",
bootstrap = [
"//:angular_bootstrap_scripts",
],
# dissable since tests are running but not yet passing
tags = ["manual"],
# do not sort
deps = [
"//packages/_testing_init:browser",
":test_lib",
],
)

View File

@ -178,7 +178,7 @@ describe('applyRedirects', () => {
applyRedirects(testModule.injector, <any>loader, serializer, tree('a/b'), config) applyRedirects(testModule.injector, <any>loader, serializer, tree('a/b'), config)
.forEach(r => { .forEach(r => {
expectTreeToBe(r, '/a/b'); expectTreeToBe(r, '/a/b');
expect(config[0]._loadedConfig).toBe(loadedConfig); expect((config[0] as any)._loadedConfig).toBe(loadedConfig);
}); });
}); });
@ -304,7 +304,7 @@ describe('applyRedirects', () => {
applyRedirects(testModule.injector, <any>loader, serializer, tree(''), config).forEach(r => { applyRedirects(testModule.injector, <any>loader, serializer, tree(''), config).forEach(r => {
expectTreeToBe(r, 'a'); expectTreeToBe(r, 'a');
expect(config[1]._loadedConfig).toBe(loadedConfig); expect((config[1] as any)._loadedConfig).toBe(loadedConfig);
}); });
}); });
@ -329,7 +329,7 @@ describe('applyRedirects', () => {
.subscribe( .subscribe(
r => { r => {
expectTreeToBe(r, 'a?k2'); expectTreeToBe(r, 'a?k2');
expect(config[0]._loadedConfig).toBe(loadedConfig); expect((config[0] as any)._loadedConfig).toBe(loadedConfig);
}, },
(e) => { throw 'Should not reach'; }); (e) => { throw 'Should not reach'; });
}); });
@ -342,7 +342,7 @@ describe('applyRedirects', () => {
const config: Routes = [{path: '**', loadChildren: 'children'}]; const config: Routes = [{path: '**', loadChildren: 'children'}];
applyRedirects(testModule.injector, <any>loader, serializer, tree('xyz'), config) applyRedirects(testModule.injector, <any>loader, serializer, tree('xyz'), config)
.forEach(r => { expect(config[0]._loadedConfig).toBe(loadedConfig); }); .forEach(r => { expect((config[0] as any)._loadedConfig).toBe(loadedConfig); });
}); });
it('should load the configuration after a local redirect from a wildcard route', () => { it('should load the configuration after a local redirect from a wildcard route', () => {
@ -354,7 +354,7 @@ describe('applyRedirects', () => {
[{path: 'not-found', loadChildren: 'children'}, {path: '**', redirectTo: 'not-found'}]; [{path: 'not-found', loadChildren: 'children'}, {path: '**', redirectTo: 'not-found'}];
applyRedirects(testModule.injector, <any>loader, serializer, tree('xyz'), config) applyRedirects(testModule.injector, <any>loader, serializer, tree('xyz'), config)
.forEach(r => { expect(config[0]._loadedConfig).toBe(loadedConfig); }); .forEach(r => { expect((config[0] as any)._loadedConfig).toBe(loadedConfig); });
}); });
it('should load the configuration after an absolute redirect from a wildcard route', () => { it('should load the configuration after an absolute redirect from a wildcard route', () => {
@ -366,7 +366,7 @@ describe('applyRedirects', () => {
[{path: 'not-found', loadChildren: 'children'}, {path: '**', redirectTo: '/not-found'}]; [{path: 'not-found', loadChildren: 'children'}, {path: '**', redirectTo: '/not-found'}];
applyRedirects(testModule.injector, <any>loader, serializer, tree('xyz'), config) applyRedirects(testModule.injector, <any>loader, serializer, tree('xyz'), config)
.forEach(r => { expect(config[0]._loadedConfig).toBe(loadedConfig); }); .forEach(r => { expect((config[0] as any)._loadedConfig).toBe(loadedConfig); });
}); });
}); });

View File

@ -214,7 +214,7 @@ describe('bootstrap', () => {
const appRef: ApplicationRef = res.injector.get(ApplicationRef); const appRef: ApplicationRef = res.injector.get(ApplicationRef);
appRef.bootstrap(SecondRootCmp); appRef.bootstrap(SecondRootCmp);
expect(router.resetRootComponentType).not.toHaveBeenCalled(); expect((router as any).resetRootComponentType).not.toHaveBeenCalled();
done(); done();
}); });
@ -240,7 +240,7 @@ describe('bootstrap', () => {
const appRef: ApplicationRef = res.injector.get(ApplicationRef); const appRef: ApplicationRef = res.injector.get(ApplicationRef);
appRef.components[0].onDestroy(() => { appRef.components[0].onDestroy(() => {
appRef.bootstrap(SecondRootCmp); appRef.bootstrap(SecondRootCmp);
expect(router.resetRootComponentType).toHaveBeenCalled(); expect((router as any).resetRootComponentType).toHaveBeenCalled();
done(); done();
}); });

View File

@ -18,8 +18,8 @@ import {TreeNode} from '../src/utils/tree';
describe('create router state', () => { describe('create router state', () => {
const reuseStrategy = new DefaultRouteReuseStrategy(); const reuseStrategy = new DefaultRouteReuseStrategy();
const emptyState = () => const emptyState = () => createEmptyState(
createEmptyState(new UrlTree(new UrlSegmentGroup([], {}), {}, null !), RootComponent); new (UrlTree as any)(new UrlSegmentGroup([], {}), {}, null !), RootComponent);
it('should work create new state', () => { it('should work create new state', () => {
const state = createRouterState( const state = createRouterState(
@ -34,7 +34,7 @@ describe('create router state', () => {
checkActivatedRoute(state.root, RootComponent); checkActivatedRoute(state.root, RootComponent);
const c = state.children(state.root); const c = (state as any).children(state.root);
checkActivatedRoute(c[0], ComponentA); checkActivatedRoute(c[0], ComponentA);
checkActivatedRoute(c[1], ComponentB, 'left'); checkActivatedRoute(c[1], ComponentB, 'left');
checkActivatedRoute(c[2], ComponentC, 'right'); checkActivatedRoute(c[2], ComponentC, 'right');
@ -52,8 +52,8 @@ describe('create router state', () => {
const state = createRouterState(reuseStrategy, createState(config, 'a(left:c)'), prevState); const state = createRouterState(reuseStrategy, createState(config, 'a(left:c)'), prevState);
expect(prevState.root).toBe(state.root); expect(prevState.root).toBe(state.root);
const prevC = prevState.children(prevState.root); const prevC = (prevState as any).children(prevState.root);
const currC = state.children(state.root); const currC = (state as any).children(state.root);
expect(prevC[0]).toBe(currC[0]); expect(prevC[0]).toBe(currC[0]);
expect(prevC[1]).not.toBe(currC[1]); expect(prevC[1]).not.toBe(currC[1]);
@ -76,11 +76,11 @@ describe('create router state', () => {
createRouterState(reuseStrategy, createState(config, 'a/2;p=22/(b//right:c)'), prevState); createRouterState(reuseStrategy, createState(config, 'a/2;p=22/(b//right:c)'), prevState);
expect(prevState.root).toBe(state.root); expect(prevState.root).toBe(state.root);
const prevP = prevState.firstChild(prevState.root) !; const prevP = (prevState as any).firstChild(prevState.root) !;
const currP = state.firstChild(state.root) !; const currP = (state as any).firstChild(state.root) !;
expect(prevP).toBe(currP); expect(prevP).toBe(currP);
const currC = state.children(currP); const currC = (state as any).children(currP);
expect(currP._futureSnapshot.params).toEqual({id: '2', p: '22'}); expect(currP._futureSnapshot.params).toEqual({id: '2', p: '22'});
expect(currP._futureSnapshot.paramMap.get('id')).toEqual('2'); expect(currP._futureSnapshot.paramMap.get('id')).toEqual('2');
@ -91,7 +91,7 @@ describe('create router state', () => {
}); });
function advanceState(state: RouterState): void { function advanceState(state: RouterState): void {
advanceNode(state._root); advanceNode((state as any)._root);
} }
function advanceNode(node: TreeNode<ActivatedRoute>): void { function advanceNode(node: TreeNode<ActivatedRoute>): void {

View File

@ -243,10 +243,10 @@ describe('createUrlTree', () => {
}); });
function createRoot(tree: UrlTree, commands: any[], queryParams?: Params, fragment?: string) { function createRoot(tree: UrlTree, commands: any[], queryParams?: Params, fragment?: string) {
const s = new ActivatedRouteSnapshot( const s = new (ActivatedRouteSnapshot as any)(
[], <any>{}, <any>{}, '', <any>{}, PRIMARY_OUTLET, 'someComponent', null, tree.root, -1, [], <any>{}, <any>{}, '', <any>{}, PRIMARY_OUTLET, 'someComponent', null, tree.root, -1,
<any>null); <any>null);
const a = new ActivatedRoute( const a = new (ActivatedRoute as any)(
new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !),
new BehaviorSubject(null !), new BehaviorSubject(null !), PRIMARY_OUTLET, 'someComponent', s); new BehaviorSubject(null !), new BehaviorSubject(null !), PRIMARY_OUTLET, 'someComponent', s);
advanceActivatedRoute(a); advanceActivatedRoute(a);
@ -259,10 +259,10 @@ function create(
if (!segment) { if (!segment) {
expect(segment).toBeDefined(); expect(segment).toBeDefined();
} }
const s = new ActivatedRouteSnapshot( const s = new (ActivatedRouteSnapshot as any)(
[], <any>{}, <any>{}, '', <any>{}, PRIMARY_OUTLET, 'someComponent', null, <any>segment, [], <any>{}, <any>{}, '', <any>{}, PRIMARY_OUTLET, 'someComponent', null, <any>segment,
startIndex, <any>null); startIndex, <any>null);
const a = new ActivatedRoute( const a = new (ActivatedRoute as any)(
new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !),
new BehaviorSubject(null !), new BehaviorSubject(null !), PRIMARY_OUTLET, 'someComponent', s); new BehaviorSubject(null !), new BehaviorSubject(null !), PRIMARY_OUTLET, 'someComponent', s);
advanceActivatedRoute(a); advanceActivatedRoute(a);

View File

@ -42,7 +42,7 @@ export declare type ARSArgs = {
}; };
export function createActivatedRouteSnapshot(args: ARSArgs): ActivatedRouteSnapshot { export function createActivatedRouteSnapshot(args: ARSArgs): ActivatedRouteSnapshot {
return new ActivatedRouteSnapshot( return new (ActivatedRouteSnapshot as any)(
args.url || <any>[], args.params || {}, args.queryParams || <any>null, args.url || <any>[], args.params || {}, args.queryParams || <any>null,
args.fragment || <any>null, args.data || <any>null, args.outlet || <any>null, args.fragment || <any>null, args.data || <any>null, args.outlet || <any>null,
<any>args.component, args.routeConfig || <any>{}, args.urlSegment || <any>null, <any>args.component, args.routeConfig || <any>{}, args.urlSegment || <any>null,

View File

@ -7,12 +7,12 @@
*/ */
import {CommonModule, Location} from '@angular/common'; import {CommonModule, Location} from '@angular/common';
import {SpyLocation} from '@angular/common/testing';
import {ChangeDetectionStrategy, Component, Injectable, NgModule, NgModuleFactoryLoader, NgModuleRef} from '@angular/core'; import {ChangeDetectionStrategy, Component, Injectable, NgModule, NgModuleFactoryLoader, NgModuleRef} from '@angular/core';
import {ComponentFixture, TestBed, fakeAsync, inject, tick} from '@angular/core/testing'; import {ComponentFixture, TestBed, fakeAsync, inject, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser/src/dom/debug/by'; import {By} from '@angular/platform-browser/src/dom/debug/by';
import {expect} from '@angular/platform-browser/testing/src/matchers'; import {expect} from '@angular/platform-browser/testing/src/matchers';
import {ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, PRIMARY_OUTLET, ParamMap, Params, PreloadAllModules, PreloadingStrategy, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouteReuseStrategy, Router, RouterEvent, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlTree} from '@angular/router'; import {ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, PRIMARY_OUTLET, ParamMap, Params, PreloadAllModules, PreloadingStrategy, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouteReuseStrategy, Router, RouterEvent, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlTree} from '@angular/router';
import {SpyLocation} from 'common/testing';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {Observer} from 'rxjs/Observer'; import {Observer} from 'rxjs/Observer';
import {of } from 'rxjs/observable/of'; import {of } from 'rxjs/observable/of';
@ -3527,7 +3527,7 @@ describe('Integration', () => {
router.navigateByUrl('/blank'); router.navigateByUrl('/blank');
advance(fixture); advance(fixture);
const config = router.config; const config = router.config as any;
const firstConfig = config[1]._loadedConfig !; const firstConfig = config[1]._loadedConfig !;
expect(firstConfig).toBeDefined(); expect(firstConfig).toBeDefined();
@ -3553,7 +3553,7 @@ describe('Integration', () => {
children[PRIMARY_OUTLET] = oldRoot.children[PRIMARY_OUTLET]; children[PRIMARY_OUTLET] = oldRoot.children[PRIMARY_OUTLET];
} }
const root = new UrlSegmentGroup(oldRoot.segments, children); const root = new UrlSegmentGroup(oldRoot.segments, children);
return new UrlTree(root, url.queryParams, url.fragment); return new (UrlTree as any)(root, url.queryParams, url.fragment);
} }
merge(newUrlPart: UrlTree, wholeUrl: UrlTree): UrlTree { merge(newUrlPart: UrlTree, wholeUrl: UrlTree): UrlTree {
@ -3571,7 +3571,7 @@ describe('Integration', () => {
v.parent = this; v.parent = this;
}); });
const root = new UrlSegmentGroup(oldRoot.segments, children); const root = new UrlSegmentGroup(oldRoot.segments, children);
return new UrlTree(root, newUrlPart.queryParams, newUrlPart.fragment); return new (UrlTree as any)(root, newUrlPart.queryParams, newUrlPart.fragment);
} }
} }
@ -3992,7 +3992,7 @@ class ComponentRecordingRoutePathAndUrl {
private url: any; private url: any;
constructor(router: Router, route: ActivatedRoute) { constructor(router: Router, route: ActivatedRoute) {
this.path = router.routerState.pathFromRoot(route); this.path = (router.routerState as any).pathFromRoot(route);
this.url = router.url.toString(); this.url = router.url.toString();
} }
} }

View File

@ -8,13 +8,13 @@
import {Routes} from '../src/config'; import {Routes} from '../src/config';
import {recognize} from '../src/recognize'; import {recognize} from '../src/recognize';
import {ActivatedRouteSnapshot, ParamsInheritanceStrategy, RouterStateSnapshot, inheritedParamsDataResolve} from '../src/router_state'; import {ActivatedRouteSnapshot, RouterStateSnapshot} from '../src/router_state';
import {PRIMARY_OUTLET, Params} from '../src/shared'; import {PRIMARY_OUTLET, Params} from '../src/shared';
import {DefaultUrlSerializer, UrlTree} from '../src/url_tree'; import {DefaultUrlSerializer, UrlTree} from '../src/url_tree';
describe('recognize', () => { describe('recognize', () => {
it('should work', () => { it('should work', () => {
checkRecognize([{path: 'a', component: ComponentA}], 'a', (s: RouterStateSnapshot) => { checkRecognize([{path: 'a', component: ComponentA}], 'a', (s: any) => {
checkActivatedRoute(s.root, '', {}, RootComponent); checkActivatedRoute(s.root, '', {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);
}); });
@ -23,7 +23,7 @@ describe('recognize', () => {
it('should freeze params object', () => { it('should freeze params object', () => {
checkRecognize([{path: 'a/:id', component: ComponentA}], 'a/10', (s: RouterStateSnapshot) => { checkRecognize([{path: 'a/:id', component: ComponentA}], 'a/10', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent); checkActivatedRoute(s.root, '', {}, RootComponent);
const child = s.firstChild(s.root) !; const child = (s as any).firstChild(s.root) !;
expect(Object.isFrozen(child.params)).toBeTruthy(); expect(Object.isFrozen(child.params)).toBeTruthy();
}); });
}); });
@ -35,7 +35,7 @@ describe('recognize', () => {
{path: 'c', component: ComponentC, outlet: 'right'} {path: 'c', component: ComponentC, outlet: 'right'}
], ],
'a(left:b//right:c)', (s: RouterStateSnapshot) => { 'a(left:b//right:c)', (s: RouterStateSnapshot) => {
const c = s.children(s.root); const c = (s as any).children(s.root);
checkActivatedRoute(c[0], 'a', {}, ComponentA); checkActivatedRoute(c[0], 'a', {}, ComponentA);
checkActivatedRoute(c[1], 'b', {}, ComponentB, 'left'); checkActivatedRoute(c[1], 'b', {}, ComponentB, 'left');
checkActivatedRoute(c[2], 'c', {}, ComponentC, 'right'); checkActivatedRoute(c[2], 'c', {}, ComponentC, 'right');
@ -51,18 +51,18 @@ describe('recognize', () => {
{path: 'c', component: ComponentC, outlet: 'right'} {path: 'c', component: ComponentC, outlet: 'right'}
], ],
url, 'a(left:b//right:c)') url, 'a(left:b//right:c)')
.subscribe((s) => { .subscribe((s: any) => {
expect(s.root._urlSegment).toBe(url.root); expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1); expect(s.root._lastPathIndex).toBe(-1);
const c = s.children(s.root); const c = (s as any).children(s.root);
expect(c[0]._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]); expect(c[0]._urlSegment).toBe((url.root as any).children[PRIMARY_OUTLET]);
expect(c[0]._lastPathIndex).toBe(0); expect(c[0]._lastPathIndex).toBe(0);
expect(c[1]._urlSegment).toBe(url.root.children['left']); expect(c[1]._urlSegment).toBe((url.root as any).children['left']);
expect(c[1]._lastPathIndex).toBe(0); expect(c[1]._lastPathIndex).toBe(0);
expect(c[2]._urlSegment).toBe(url.root.children['right']); expect(c[2]._urlSegment).toBe((url.root as any).children['right']);
expect(c[2]._lastPathIndex).toBe(0); expect(c[2]._lastPathIndex).toBe(0);
}); });
}); });
@ -76,15 +76,15 @@ describe('recognize', () => {
], ],
url, 'a/b/c') url, 'a/b/c')
.subscribe((s: RouterStateSnapshot) => { .subscribe((s: RouterStateSnapshot) => {
expect(s.root._urlSegment).toBe(url.root); expect((s.root as any)._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1); expect((s.root as any)._lastPathIndex).toBe(-1);
const compA = s.firstChild(s.root) !; const compA = (s as any).firstChild(s.root) !;
expect(compA._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]); expect(compA._urlSegment).toBe((url.root as any).children[PRIMARY_OUTLET]);
expect(compA._lastPathIndex).toBe(1); expect(compA._lastPathIndex).toBe(1);
const compC = s.firstChild(<any>compA) !; const compC = (s as any).firstChild(<any>compA) !;
expect(compC._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]); expect(compC._urlSegment).toBe((url.root as any).children[PRIMARY_OUTLET]);
expect(compC._lastPathIndex).toBe(2); expect(compC._lastPathIndex).toBe(2);
}); });
}); });
@ -97,16 +97,16 @@ describe('recognize', () => {
{path: 'a', component: ComponentA, children: [{path: '**', component: ComponentB}]}, {path: 'a', component: ComponentA, children: [{path: '**', component: ComponentB}]},
], ],
url, 'a/b/c') url, 'a/b/c')
.subscribe((s: RouterStateSnapshot) => { .subscribe((s: any) => {
expect(s.root._urlSegment).toBe(url.root); expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1); expect(s.root._lastPathIndex).toBe(-1);
const compA = s.firstChild(s.root) !; const compA = (s as any).firstChild(s.root) !;
expect(compA._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]); expect(compA._urlSegment).toBe((url as any).root.children[PRIMARY_OUTLET]);
expect(compA._lastPathIndex).toBe(0); expect(compA._lastPathIndex).toBe(0);
const compC = s.firstChild(<any>compA) !; const compC = (s as any).firstChild(<any>compA) !;
expect(compC._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]); expect(compC._urlSegment).toBe((url as any).root.children[PRIMARY_OUTLET]);
expect(compC._lastPathIndex).toBe(2); expect(compC._lastPathIndex).toBe(2);
}); });
}); });
@ -119,16 +119,18 @@ describe('recognize', () => {
], ],
'a/paramA', (s: RouterStateSnapshot) => { 'a/paramA', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent); checkActivatedRoute(s.root, '', {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
checkActivatedRoute( checkActivatedRoute(
s.firstChild(<any>s.firstChild(s.root)) !, 'paramA', {id: 'paramA'}, ComponentB); (s as any).firstChild(<any>(s as any).firstChild(s.root)) !, 'paramA', {id: 'paramA'},
ComponentB);
}); });
checkRecognize( checkRecognize(
[{path: 'a', component: ComponentA}, {path: 'a/:id', component: ComponentC}], 'a/paramA', [{path: 'a', component: ComponentA}, {path: 'a/:id', component: ComponentC}], 'a/paramA',
(s: RouterStateSnapshot) => { (s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent); checkActivatedRoute(s.root, '', {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root) !, 'a/paramA', {id: 'paramA'}, ComponentC); checkActivatedRoute(
(s as any).firstChild(s.root) !, 'a/paramA', {id: 'paramA'}, ComponentC);
}); });
}); });
@ -139,7 +141,7 @@ describe('recognize', () => {
{path: 'b', component: ComponentC, outlet: 'right'} {path: 'b', component: ComponentC, outlet: 'right'}
], ],
'a(right:b)', (s: RouterStateSnapshot) => { 'a(right:b)', (s: RouterStateSnapshot) => {
const c = s.children(s.root); const c = (s as any).children(s.root);
checkActivatedRoute(c[0], 'a', {}, ComponentA); checkActivatedRoute(c[0], 'a', {}, ComponentA);
checkActivatedRoute(c[1], 'b', {}, ComponentC, 'right'); checkActivatedRoute(c[1], 'b', {}, ComponentC, 'right');
}); });
@ -158,7 +160,7 @@ describe('recognize', () => {
}, },
], ],
'a/(b//left:c)', (s: RouterStateSnapshot) => { 'a/(b//left:c)', (s: RouterStateSnapshot) => {
const c = s.children(<any>s.firstChild(s.root)); const c = (s as any).children(<any>(s as any).firstChild(s.root));
checkActivatedRoute(c[0], 'b', {}, ComponentB, PRIMARY_OUTLET); checkActivatedRoute(c[0], 'b', {}, ComponentB, PRIMARY_OUTLET);
checkActivatedRoute(c[1], 'c', {}, ComponentC, 'left'); checkActivatedRoute(c[1], 'c', {}, ComponentC, 'left');
}); });
@ -171,7 +173,7 @@ describe('recognize', () => {
{path: 'b', component: ComponentB, outlet: 'b'} {path: 'b', component: ComponentB, outlet: 'b'}
], ],
'a(c:c//b:b)', (s: RouterStateSnapshot) => { 'a(c:c//b:b)', (s: RouterStateSnapshot) => {
const c = s.children(s.root); const c = (s as any).children(s.root);
checkActivatedRoute(c[0], 'a', {}, ComponentA); checkActivatedRoute(c[0], 'a', {}, ComponentA);
checkActivatedRoute(c[1], 'b', {}, ComponentB, 'b'); checkActivatedRoute(c[1], 'b', {}, ComponentB, 'b');
checkActivatedRoute(c[2], 'c', {}, ComponentC, 'c'); checkActivatedRoute(c[2], 'c', {}, ComponentC, 'c');
@ -185,9 +187,10 @@ describe('recognize', () => {
{path: 'c', component: ComponentC, outlet: 'left'} {path: 'c', component: ComponentC, outlet: 'left'}
], ],
'a;a1=11;a2=22/b;b1=111;b2=222(left:c;c1=1111;c2=2222)', (s: RouterStateSnapshot) => { 'a;a1=11;a2=22/b;b1=111;b2=222(left:c;c1=1111;c2=2222)', (s: RouterStateSnapshot) => {
const c = s.children(s.root); const c = (s as any).children(s.root);
checkActivatedRoute(c[0], 'a', {a1: '11', a2: '22'}, ComponentA); checkActivatedRoute(c[0], 'a', {a1: '11', a2: '22'}, ComponentA);
checkActivatedRoute(s.firstChild(<any>c[0]) !, 'b', {b1: '111', b2: '222'}, ComponentB); checkActivatedRoute(
(s as any).firstChild(<any>c[0]) !, 'b', {b1: '111', b2: '222'}, ComponentB);
checkActivatedRoute(c[1], 'c', {c1: '1111', c2: '2222'}, ComponentC, 'left'); checkActivatedRoute(c[1], 'c', {c1: '1111', c2: '2222'}, ComponentC, 'left');
}); });
}); });
@ -196,7 +199,7 @@ describe('recognize', () => {
it('should set static data', () => { it('should set static data', () => {
checkRecognize( checkRecognize(
[{path: 'a', data: {one: 1}, component: ComponentA}], 'a', (s: RouterStateSnapshot) => { [{path: 'a', data: {one: 1}, component: ComponentA}], 'a', (s: RouterStateSnapshot) => {
const r: ActivatedRouteSnapshot = s.firstChild(s.root) !; const r: ActivatedRouteSnapshot = (s as any).firstChild(s.root) !;
expect(r.data).toEqual({one: 1}); expect(r.data).toEqual({one: 1});
}); });
}); });
@ -209,7 +212,8 @@ describe('recognize', () => {
children: [{path: 'b', data: {two: 2}, component: ComponentB}] children: [{path: 'b', data: {two: 2}, component: ComponentB}]
}], }],
'a/b', (s: RouterStateSnapshot) => { 'a/b', (s: RouterStateSnapshot) => {
const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root)) !; const r: ActivatedRouteSnapshot =
(s as any).firstChild(<any>(s as any).firstChild(s.root)) !;
expect(r.data).toEqual({one: 1, two: 2}); expect(r.data).toEqual({one: 1, two: 2});
}); });
}); });
@ -222,7 +226,7 @@ describe('recognize', () => {
data: {one: 1}, data: {one: 1},
children: [{path: 'b', data: {two: 2}, component: ComponentB}] children: [{path: 'b', data: {two: 2}, component: ComponentB}]
}], }],
'a/b', (s: RouterStateSnapshot) => { 'a/b', (s: any /* RouterStateSnapshot */) => {
const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root)) !; const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root)) !;
expect(r.data).toEqual({two: 2}); expect(r.data).toEqual({two: 2});
}); });
@ -236,7 +240,7 @@ describe('recognize', () => {
data: {one: 1}, data: {one: 1},
children: [{path: 'b', data: {two: 2}, component: ComponentB}] children: [{path: 'b', data: {two: 2}, component: ComponentB}]
}], }],
'a/b', (s: RouterStateSnapshot) => { 'a/b', (s: any /* RouterStateSnapshot */) => {
const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root)) !; const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root)) !;
expect(r.data).toEqual({one: 1, two: 2}); expect(r.data).toEqual({one: 1, two: 2});
}, 'always'); }, 'always');
@ -244,9 +248,8 @@ describe('recognize', () => {
it('should set resolved data', () => { it('should set resolved data', () => {
checkRecognize( checkRecognize(
[{path: 'a', resolve: {one: 'some-token'}, component: ComponentA}], 'a', [{path: 'a', resolve: {one: 'some-token'}, component: ComponentA}], 'a', (s: any) => {
(s: RouterStateSnapshot) => { const r: any = s.firstChild(s.root) !;
const r: ActivatedRouteSnapshot = s.firstChild(s.root) !;
expect(r._resolve).toEqual({one: 'some-token'}); expect(r._resolve).toEqual({one: 'some-token'});
}); });
}); });
@ -256,7 +259,7 @@ describe('recognize', () => {
describe('root', () => { describe('root', () => {
it('should work', () => { it('should work', () => {
checkRecognize([{path: '', component: ComponentA}], '', (s: RouterStateSnapshot) => { checkRecognize([{path: '', component: ComponentA}], '', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, '', {}, ComponentA);
}); });
}); });
@ -264,7 +267,7 @@ describe('recognize', () => {
checkRecognize( checkRecognize(
[{path: '', pathMatch: 'full', component: ComponentA}], '', [{path: '', pathMatch: 'full', component: ComponentA}], '',
(s: RouterStateSnapshot) => { (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, '', {}, ComponentA);
}); });
}); });
@ -272,18 +275,19 @@ describe('recognize', () => {
checkRecognize( checkRecognize(
[{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], '', [{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], '',
(s: RouterStateSnapshot) => { (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, '', {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)) !, '', {}, ComponentB); checkActivatedRoute(
(s as any).firstChild(<any>(s as any).firstChild(s.root)) !, '', {}, ComponentB);
}); });
}); });
it('should set url segment and index properly', () => { it('should set url segment and index properly', () => {
const url = tree(''); const url = tree('') as any;
recognize( recognize(
RootComponent, RootComponent,
[{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], url, [{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], url,
'') '')
.forEach((s: RouterStateSnapshot) => { .forEach((s: any) => {
expect(s.root._urlSegment).toBe(url.root); expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1); expect(s.root._lastPathIndex).toBe(-1);
@ -307,10 +311,13 @@ describe('recognize', () => {
] ]
}], }],
'/a;p=1', (s: RouterStateSnapshot) => { '/a;p=1', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {p: '1'}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {p: '1'}, ComponentA);
checkActivatedRoute(s.firstChild(s.firstChild(s.root) !) !, '', {p: '1'}, ComponentB);
checkActivatedRoute( checkActivatedRoute(
s.firstChild(s.firstChild(s.firstChild(s.root) !) !) !, '', {p: '1'}, ComponentC); (s as any).firstChild((s as any).firstChild(s.root) !) !, '', {p: '1'},
ComponentB);
checkActivatedRoute(
(s as any).firstChild((s as any).firstChild((s as any).firstChild(s.root) !) !) !,
'', {p: '1'}, ComponentC);
}); });
}); });
}); });
@ -327,9 +334,9 @@ describe('recognize', () => {
] ]
}], }],
'a/b', (s: RouterStateSnapshot) => { 'a/b', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !); const c = (s as any).children((s as any).firstChild(s.root) !);
checkActivatedRoute(c[0], 'b', {}, ComponentB); checkActivatedRoute(c[0], 'b', {}, ComponentB);
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
}); });
@ -358,13 +365,13 @@ describe('recognize', () => {
checkRecognize(config, 'parent/b', (s: RouterStateSnapshot) => { checkRecognize(config, 'parent/b', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent); checkActivatedRoute(s.root, '', {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root) !, 'parent', {}, undefined !); checkActivatedRoute((s as any).firstChild(s.root) !, 'parent', {}, undefined !);
const cc = s.children(s.firstChild(s.root) !); const cc = (s as any).children((s as any).firstChild(s.root) !);
checkActivatedRoute(cc[0], '', {}, ComponentA); checkActivatedRoute(cc[0], '', {}, ComponentA);
checkActivatedRoute(cc[1], '', {}, ComponentD, 'secondary'); checkActivatedRoute(cc[1], '', {}, ComponentD, 'secondary');
checkActivatedRoute(s.firstChild(cc[0]) !, 'b', {}, ComponentB); checkActivatedRoute((s as any).firstChild(cc[0]) !, 'b', {}, ComponentB);
}); });
}); });
@ -379,16 +386,16 @@ describe('recognize', () => {
] ]
}], }],
'a/b', (s: RouterStateSnapshot) => { 'a/b', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !); const c = (s as any).children((s as any).firstChild(s.root) !);
expect(c.length).toEqual(1); expect(c.length).toEqual(1);
checkActivatedRoute(c[0], 'b', {}, ComponentB); checkActivatedRoute(c[0], 'b', {}, ComponentB);
}); });
}); });
it('should set url segment and index properly', () => { it('should set url segment and index properly', () => {
const url = tree('a/b'); const url = tree('a/b') as any;
recognize( recognize(
RootComponent, [{ RootComponent, [{
path: 'a', path: 'a',
@ -399,7 +406,7 @@ describe('recognize', () => {
] ]
}], }],
url, 'a/b') url, 'a/b')
.forEach((s: RouterStateSnapshot) => { .forEach((s: any) => {
expect(s.root._urlSegment).toBe(url.root); expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1); expect(s.root._lastPathIndex).toBe(-1);
@ -418,7 +425,7 @@ describe('recognize', () => {
}); });
it('should set url segment and index properly when nested empty-path segments', () => { it('should set url segment and index properly when nested empty-path segments', () => {
const url = tree('a'); const url = tree('a') as any;
recognize( recognize(
RootComponent, [{ RootComponent, [{
path: 'a', path: 'a',
@ -427,7 +434,7 @@ describe('recognize', () => {
] ]
}], }],
url, 'a') url, 'a')
.forEach((s: RouterStateSnapshot) => { .forEach((s: any) => {
expect(s.root._urlSegment).toBe(url.root); expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1); expect(s.root._lastPathIndex).toBe(-1);
@ -455,19 +462,19 @@ describe('recognize', () => {
] ]
}], }],
url, '') url, '')
.forEach((s: RouterStateSnapshot) => { .forEach((s: any) => {
expect(s.root._urlSegment).toBe(url.root); expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1); expect(s.root._lastPathIndex).toBe(-1);
const a = s.firstChild(s.root) !; const a = (s as any).firstChild(s.root) !;
expect(a._urlSegment).toBe(url.root); expect(a._urlSegment).toBe(url.root);
expect(a._lastPathIndex).toBe(-1); expect(a._lastPathIndex).toBe(-1);
const b = s.firstChild(a) !; const b = (s as any).firstChild(a) !;
expect(b._urlSegment).toBe(url.root); expect(b._urlSegment).toBe(url.root);
expect(b._lastPathIndex).toBe(-1); expect(b._lastPathIndex).toBe(-1);
const c = s.firstChild(b) !; const c = (s as any).firstChild(b) !;
expect(c._urlSegment).toBe(url.root); expect(c._urlSegment).toBe(url.root);
expect(c._lastPathIndex).toBe(-1); expect(c._lastPathIndex).toBe(-1);
}); });
@ -486,9 +493,9 @@ describe('recognize', () => {
] ]
}], }],
'a', (s: RouterStateSnapshot) => { 'a', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !); const c = (s as any).children((s as any).firstChild(s.root) !);
checkActivatedRoute(c[0], '', {}, ComponentB); checkActivatedRoute(c[0], '', {}, ComponentB);
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
}); });
@ -505,9 +512,9 @@ describe('recognize', () => {
] ]
}], }],
'a', (s: RouterStateSnapshot) => { 'a', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !); const c = (s as any).children((s as any).firstChild(s.root) !);
checkActivatedRoute(c[0], '', {}, ComponentB); checkActivatedRoute(c[0], '', {}, ComponentB);
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
}); });
@ -524,9 +531,9 @@ describe('recognize', () => {
] ]
}], }],
'a/(aux:c)', (s: RouterStateSnapshot) => { 'a/(aux:c)', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !); const c = (s as any).children((s as any).firstChild(s.root) !);
checkActivatedRoute(c[0], '', {}, ComponentB); checkActivatedRoute(c[0], '', {}, ComponentB);
checkActivatedRoute(c[1], 'c', {}, ComponentC, 'aux'); checkActivatedRoute(c[1], 'c', {}, ComponentC, 'aux');
}); });
@ -541,7 +548,7 @@ describe('recognize', () => {
'(aux:c)', (s: RouterStateSnapshot) => { '(aux:c)', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent); checkActivatedRoute(s.root, '', {}, RootComponent);
const children = s.children(s.root); const children = (s as any).children(s.root);
expect(children.length).toEqual(2); expect(children.length).toEqual(2);
checkActivatedRoute(children[0], '', {}, ComponentA); checkActivatedRoute(children[0], '', {}, ComponentA);
checkActivatedRoute(children[1], 'c', {}, ComponentC, 'aux'); checkActivatedRoute(children[1], 'c', {}, ComponentC, 'aux');
@ -566,13 +573,13 @@ describe('recognize', () => {
] ]
}], }],
'a/(d//aux:e)', (s: RouterStateSnapshot) => { 'a/(d//aux:e)', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !); const c = (s as any).children((s as any).firstChild(s.root) !);
checkActivatedRoute(c[0], '', {}, ComponentB); checkActivatedRoute(c[0], '', {}, ComponentB);
checkActivatedRoute(s.firstChild(c[0]) !, 'd', {}, ComponentD); checkActivatedRoute((s as any).firstChild(c[0]) !, 'd', {}, ComponentD);
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux'); checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
checkActivatedRoute(s.firstChild(c[1]) !, 'e', {}, ComponentE); checkActivatedRoute((s as any).firstChild(c[1]) !, 'e', {}, ComponentE);
}); });
}); });
}); });
@ -582,7 +589,7 @@ describe('recognize', () => {
it('should support simple wildcards', () => { it('should support simple wildcards', () => {
checkRecognize( checkRecognize(
[{path: '**', component: ComponentA}], 'a/b/c/d;a1=11', (s: RouterStateSnapshot) => { [{path: '**', component: ComponentA}], 'a/b/c/d;a1=11', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a/b/c/d', {a1: '11'}, ComponentA); checkActivatedRoute((s as any).firstChild(s.root) !, 'a/b/c/d', {a1: '11'}, ComponentA);
}); });
}); });
}); });
@ -598,10 +605,10 @@ describe('recognize', () => {
] ]
}], }],
'p/11;pp=22/(a;pa=33//aux:b;pb=44)', (s: RouterStateSnapshot) => { 'p/11;pp=22/(a;pa=33//aux:b;pb=44)', (s: RouterStateSnapshot) => {
const p = s.firstChild(s.root) !; const p = (s as any).firstChild(s.root) !;
checkActivatedRoute(p, 'p/11', {id: '11', pp: '22'}, undefined !); checkActivatedRoute(p, 'p/11', {id: '11', pp: '22'}, undefined !);
const c = s.children(p); const c = (s as any).children(p);
checkActivatedRoute(c[0], 'a', {id: '11', pp: '22', pa: '33'}, ComponentA); checkActivatedRoute(c[0], 'a', {id: '11', pp: '22', pa: '33'}, ComponentA);
checkActivatedRoute(c[1], 'b', {id: '11', pp: '22', pb: '44'}, ComponentB, 'aux'); checkActivatedRoute(c[1], 'b', {id: '11', pp: '22', pb: '44'}, ComponentB, 'aux');
}); });
@ -621,16 +628,16 @@ describe('recognize', () => {
}] }]
}], }],
'p/11/a/victor/b/c', (s: RouterStateSnapshot) => { 'p/11/a/victor/b/c', (s: RouterStateSnapshot) => {
const p = s.firstChild(s.root) !; const p = (s as any).firstChild(s.root) !;
checkActivatedRoute(p, 'p/11', {id: '11'}, undefined !); checkActivatedRoute(p, 'p/11', {id: '11'}, undefined !);
const a = s.firstChild(p) !; const a = (s as any).firstChild(p) !;
checkActivatedRoute(a, 'a/victor', {id: '11', name: 'victor'}, undefined !); checkActivatedRoute(a, 'a/victor', {id: '11', name: 'victor'}, undefined !);
const b = s.firstChild(a) !; const b = (s as any).firstChild(a) !;
checkActivatedRoute(b, 'b', {id: '11', name: 'victor'}, ComponentB); checkActivatedRoute(b, 'b', {id: '11', name: 'victor'}, ComponentB);
const c = s.firstChild(b) !; const c = (s as any).firstChild(b) !;
checkActivatedRoute(c, 'c', {}, ComponentC); checkActivatedRoute(c, 'c', {}, ComponentC);
}); });
}); });
@ -648,7 +655,7 @@ describe('recognize', () => {
}] }]
}] }]
}], }],
'p/11/a/victor/b/c', (s: RouterStateSnapshot) => { 'p/11/a/victor/b/c', (s: any /* RouterStateSnapshot */) => {
const c = s.firstChild(s.firstChild(s.firstChild(s.firstChild(s.root) !) !) !) !; const c = s.firstChild(s.firstChild(s.firstChild(s.firstChild(s.root) !) !) !) !;
checkActivatedRoute(c, 'c', {id: '11', name: 'victor'}, ComponentC); checkActivatedRoute(c, 'c', {id: '11', name: 'victor'}, ComponentC);
}, 'always'); }, 'always');
@ -660,7 +667,7 @@ describe('recognize', () => {
checkRecognize( checkRecognize(
[{path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}], [{path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}],
'/a', (s: RouterStateSnapshot) => { '/a', (s: RouterStateSnapshot) => {
const a = s.firstChild(s.root); const a = (s as any).firstChild(s.root);
checkActivatedRoute(a !, 'a', {}, ComponentA); checkActivatedRoute(a !, 'a', {}, ComponentA);
}); });
}); });
@ -676,9 +683,9 @@ describe('recognize', () => {
] ]
}], }],
'/a', (s: RouterStateSnapshot) => { '/a', (s: RouterStateSnapshot) => {
const a = s.firstChild(s.root) !; const a = (s as any).firstChild(s.root) !;
checkActivatedRoute(a, 'a', {}, ComponentA); checkActivatedRoute(a, 'a', {}, ComponentA);
checkActivatedRoute(a.children[0], '', {}, ComponentC, 'aux'); checkActivatedRoute((a as any).children[0], '', {}, ComponentC, 'aux');
}); });
}); });
}); });
@ -700,9 +707,9 @@ describe('recognize', () => {
children: [{path: 'b', component: ComponentB}] children: [{path: 'b', component: ComponentB}]
}] as any, }] as any,
'/a/1;p=99/b', (s: RouterStateSnapshot) => { '/a/1;p=99/b', (s: RouterStateSnapshot) => {
const a = s.root.firstChild !; const a = (s as any).root.firstChild !;
checkActivatedRoute(a, 'a/1', {id: '1', p: '99'}, ComponentA); checkActivatedRoute(a, 'a/1', {id: '1', p: '99'}, ComponentA);
checkActivatedRoute(a.firstChild !, 'b', {}, ComponentB); checkActivatedRoute((a as any).firstChild !, 'b', {}, ComponentB);
}); });
}); });
@ -710,7 +717,7 @@ describe('recognize', () => {
const matcher = (s: any, g: any, r: any) => s.length === 0 ? ({consumed: s}) : null; const matcher = (s: any, g: any, r: any) => s.length === 0 ? ({consumed: s}) : null;
checkRecognize([{matcher, component: ComponentA}] as any, '', (s: RouterStateSnapshot) => { checkRecognize([{matcher, component: ComponentA}] as any, '', (s: RouterStateSnapshot) => {
const a = s.root.firstChild !; const a = (s as any).root.firstChild !;
checkActivatedRoute(a, '', {}, ComponentA); checkActivatedRoute(a, '', {}, ComponentA);
}); });
}); });
@ -721,7 +728,7 @@ describe('recognize', () => {
checkRecognize( checkRecognize(
[{path: 'a', component: ComponentA, children: [{matcher, component: ComponentB}]}] as any, [{path: 'a', component: ComponentA, children: [{matcher, component: ComponentB}]}] as any,
'a', (s: RouterStateSnapshot) => { 'a', (s: RouterStateSnapshot) => {
const a = s.root.firstChild !; const a = (s as any).root.firstChild !;
checkActivatedRoute(a, 'a', {}, ComponentA); checkActivatedRoute(a, 'a', {}, ComponentA);
}); });
}); });
@ -771,7 +778,7 @@ describe('recognize', () => {
function checkRecognize( function checkRecognize(
config: Routes, url: string, callback: any, config: Routes, url: string, callback: any,
paramsInheritanceStrategy?: ParamsInheritanceStrategy): void { paramsInheritanceStrategy?: 'emptyOnly' | 'always'): void {
recognize(RootComponent, config, tree(url), url, paramsInheritanceStrategy) recognize(RootComponent, config, tree(url), url, paramsInheritanceStrategy)
.subscribe(callback, e => { throw e; }); .subscribe(callback, e => { throw e; });
} }

View File

@ -31,7 +31,7 @@ describe('Router', () => {
const r: Router = TestBed.get(Router); const r: Router = TestBed.get(Router);
const root = r.routerState.root; const root = r.routerState.root;
r.resetRootComponentType(NewRootComponent); (r as any).resetRootComponentType(NewRootComponent);
expect(r.routerState.root).toBe(root); expect(r.routerState.root).toBe(root);
}); });
@ -103,7 +103,7 @@ describe('Router', () => {
let result = false; let result = false;
const childSnapshot = const childSnapshot =
createActivatedRouteSnapshot({component: 'child', routeConfig: {path: 'child'}}); createActivatedRouteSnapshot({component: 'child', routeConfig: {path: 'child'}});
const futureState = new RouterStateSnapshot( const futureState = new (RouterStateSnapshot as any)(
'url', new TreeNode(empty.root, [new TreeNode(childSnapshot, [])])); 'url', new TreeNode(empty.root, [new TreeNode(childSnapshot, [])]));
const p = new PreActivation(futureState, empty, TestBed, (evt) => { events.push(evt); }); const p = new PreActivation(futureState, empty, TestBed, (evt) => { events.push(evt); });
@ -132,7 +132,7 @@ describe('Router', () => {
{component: 'grandchild', routeConfig: {path: 'grandchild'}}); {component: 'grandchild', routeConfig: {path: 'grandchild'}});
const greatGrandchildSnapshot = createActivatedRouteSnapshot( const greatGrandchildSnapshot = createActivatedRouteSnapshot(
{component: 'great-grandchild', routeConfig: {path: 'great-grandchild'}}); {component: 'great-grandchild', routeConfig: {path: 'great-grandchild'}});
const futureState = new RouterStateSnapshot( const futureState = new (RouterStateSnapshot as any)(
'url', 'url',
new TreeNode( new TreeNode(
empty.root, [new TreeNode(childSnapshot, [ empty.root, [new TreeNode(childSnapshot, [
@ -164,9 +164,9 @@ describe('Router', () => {
createActivatedRouteSnapshot({component: 'child', routeConfig: {path: 'child'}}); createActivatedRouteSnapshot({component: 'child', routeConfig: {path: 'child'}});
const grandchildSnapshot = createActivatedRouteSnapshot( const grandchildSnapshot = createActivatedRouteSnapshot(
{component: 'grandchild', routeConfig: {path: 'grandchild'}}); {component: 'grandchild', routeConfig: {path: 'grandchild'}});
const currentState = new RouterStateSnapshot( const currentState = new (RouterStateSnapshot as any)(
'url', new TreeNode(empty.root, [new TreeNode(childSnapshot, [])])); 'url', new TreeNode(empty.root, [new TreeNode(childSnapshot, [])]));
const futureState = new RouterStateSnapshot( const futureState = new (RouterStateSnapshot as any)(
'url', 'url',
new TreeNode( new TreeNode(
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
@ -203,11 +203,11 @@ describe('Router', () => {
{component: 'greatgrandchild', routeConfig: {path: 'greatgrandchild'}}); {component: 'greatgrandchild', routeConfig: {path: 'greatgrandchild'}});
const greatGreatGrandchildSnapshot = createActivatedRouteSnapshot( const greatGreatGrandchildSnapshot = createActivatedRouteSnapshot(
{component: 'great-greatgrandchild', routeConfig: {path: 'great-greatgrandchild'}}); {component: 'great-greatgrandchild', routeConfig: {path: 'great-greatgrandchild'}});
const currentState = new RouterStateSnapshot( const currentState = new (RouterStateSnapshot as any)(
'url', 'url',
new TreeNode( new TreeNode(
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
const futureState = new RouterStateSnapshot( const futureState = new (RouterStateSnapshot as any)(
'url', 'url',
new TreeNode( new TreeNode(
empty.root, empty.root,
@ -252,7 +252,7 @@ describe('Router', () => {
const grandchildSnapshot = createActivatedRouteSnapshot( const grandchildSnapshot = createActivatedRouteSnapshot(
{component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}});
const futureState = new RouterStateSnapshot( const futureState = new (RouterStateSnapshot as any)(
'url', 'url',
new TreeNode( new TreeNode(
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
@ -279,7 +279,7 @@ describe('Router', () => {
const grandchildSnapshot = createActivatedRouteSnapshot( const grandchildSnapshot = createActivatedRouteSnapshot(
{component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}});
const futureState = new RouterStateSnapshot( const futureState = new (RouterStateSnapshot as any)(
'url', 'url',
new TreeNode( new TreeNode(
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
@ -306,7 +306,7 @@ describe('Router', () => {
const grandchildSnapshot = createActivatedRouteSnapshot( const grandchildSnapshot = createActivatedRouteSnapshot(
{component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}});
const futureState = new RouterStateSnapshot( const futureState = new (RouterStateSnapshot as any)(
'url', 'url',
new TreeNode( new TreeNode(
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
@ -337,10 +337,10 @@ describe('Router', () => {
const grandchildSnapshot = createActivatedRouteSnapshot( const grandchildSnapshot = createActivatedRouteSnapshot(
{component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}});
const currentState = new RouterStateSnapshot( const currentState = new (RouterStateSnapshot as any)(
'prev', new TreeNode(empty.root, [new TreeNode(prevSnapshot, [])])); 'prev', new TreeNode(empty.root, [new TreeNode(prevSnapshot, [])]));
const futureState = new RouterStateSnapshot( const futureState = new (RouterStateSnapshot as any)(
'url', 'url',
new TreeNode( new TreeNode(
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
@ -368,9 +368,9 @@ describe('Router', () => {
const grandchildSnapshot = createActivatedRouteSnapshot( const grandchildSnapshot = createActivatedRouteSnapshot(
{component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}});
const currentState = new RouterStateSnapshot( const currentState = new (RouterStateSnapshot as any)(
'prev', new TreeNode(empty.root, [new TreeNode(prevSnapshot, [])])); 'prev', new TreeNode(empty.root, [new TreeNode(prevSnapshot, [])]));
const futureState = new RouterStateSnapshot( const futureState = new (RouterStateSnapshot as any)(
'url', 'url',
new TreeNode( new TreeNode(
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
@ -400,12 +400,12 @@ describe('Router', () => {
const grandchildSnapshot = createActivatedRouteSnapshot( const grandchildSnapshot = createActivatedRouteSnapshot(
{component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}}); {component: 'grandchild', routeConfig: {canActivate: [CA_GRANDCHILD]}});
const currentState = new RouterStateSnapshot( const currentState = new (RouterStateSnapshot as any)(
'prev', new TreeNode(empty.root, [ 'prev', new TreeNode(empty.root, [
new TreeNode(prevChildSnapshot, [new TreeNode(prevGrandchildSnapshot, [])]) new TreeNode(prevChildSnapshot, [new TreeNode(prevGrandchildSnapshot, [])])
])); ]));
const futureState = new RouterStateSnapshot( const futureState = new (RouterStateSnapshot as any)(
'url', 'url',
new TreeNode( new TreeNode(
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])])); empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
@ -435,7 +435,8 @@ describe('Router', () => {
*/ */
const r = {data: 'resolver'}; const r = {data: 'resolver'};
const n = createActivatedRouteSnapshot({component: 'a', resolve: r}); const n = createActivatedRouteSnapshot({component: 'a', resolve: r});
const s = new RouterStateSnapshot('url', new TreeNode(empty.root, [new TreeNode(n, [])])); const s = new (RouterStateSnapshot as any)(
'url', new TreeNode(empty.root, [new TreeNode(n, [])]));
checkResolveData(s, empty, inj, () => { checkResolveData(s, empty, inj, () => {
expect(s.root.firstChild !.data).toEqual({data: 'resolver_value'}); expect(s.root.firstChild !.data).toEqual({data: 'resolver_value'});
@ -456,7 +457,7 @@ describe('Router', () => {
const parent = createActivatedRouteSnapshot({component: null !, resolve: parentResolve}); const parent = createActivatedRouteSnapshot({component: null !, resolve: parentResolve});
const child = createActivatedRouteSnapshot({component: 'b', resolve: childResolve}); const child = createActivatedRouteSnapshot({component: 'b', resolve: childResolve});
const s = new RouterStateSnapshot( const s = new (RouterStateSnapshot as any)(
'url', new TreeNode(empty.root, [new TreeNode(parent, [new TreeNode(child, [])])])); 'url', new TreeNode(empty.root, [new TreeNode(parent, [new TreeNode(child, [])])]));
const inj = {get: (token: any) => () => Promise.resolve(`${token}_value`)}; const inj = {get: (token: any) => () => Promise.resolve(`${token}_value`)};
@ -478,12 +479,13 @@ describe('Router', () => {
const r2 = {data: 'resolver2'}; const r2 = {data: 'resolver2'};
const n1 = createActivatedRouteSnapshot({component: 'a', resolve: r1}); const n1 = createActivatedRouteSnapshot({component: 'a', resolve: r1});
const s1 = new RouterStateSnapshot('url', new TreeNode(empty.root, [new TreeNode(n1, [])])); const s1 = new (RouterStateSnapshot as any)(
'url', new TreeNode(empty.root, [new TreeNode(n1, [])]));
checkResolveData(s1, empty, inj, () => {}); checkResolveData(s1, empty, inj, () => {});
const n21 = createActivatedRouteSnapshot({component: 'a', resolve: r1}); const n21 = createActivatedRouteSnapshot({component: 'a', resolve: r1});
const n22 = createActivatedRouteSnapshot({component: 'b', resolve: r2}); const n22 = createActivatedRouteSnapshot({component: 'b', resolve: r2});
const s2 = new RouterStateSnapshot( const s2 = new (RouterStateSnapshot as any)(
'url', new TreeNode(empty.root, [new TreeNode(n21, [new TreeNode(n22, [])])])); 'url', new TreeNode(empty.root, [new TreeNode(n21, [new TreeNode(n22, [])])]));
checkResolveData(s2, s1, inj, () => { checkResolveData(s2, s1, inj, () => {
expect(s2.root.firstChild !.data).toEqual({data: 'resolver1_value'}); expect(s2.root.firstChild !.data).toEqual({data: 'resolver1_value'});

View File

@ -46,7 +46,7 @@ describe('RouterPreloader', () => {
tick(); tick();
const c = router.config; const c = router.config;
expect(c[0]._loadedConfig).not.toBeDefined(); expect((c[0] as any)._loadedConfig).not.toBeDefined();
}))); })));
}); });
@ -97,12 +97,13 @@ describe('RouterPreloader', () => {
const c = router.config; const c = router.config;
expect(c[0].loadChildren).toEqual('expected'); expect(c[0].loadChildren).toEqual('expected');
const loadedConfig: LoadedRouterConfig = c[0]._loadedConfig !; const loadedConfig: LoadedRouterConfig = (c[0] as any)._loadedConfig !;
const module: any = loadedConfig.module; const module: any = loadedConfig.module;
expect(loadedConfig.routes[0].path).toEqual('LoadedModule1'); expect(loadedConfig.routes[0].path).toEqual('LoadedModule1');
expect(module._parent).toBe(testModule); expect(module._parent).toBe(testModule);
const loadedConfig2: LoadedRouterConfig = loadedConfig.routes[0]._loadedConfig !; const loadedConfig2: LoadedRouterConfig =
(loadedConfig.routes[0] as any)._loadedConfig !;
const module2: any = loadedConfig2.module; const module2: any = loadedConfig2.module;
expect(loadedConfig2.routes[0].path).toEqual('LoadedModule2'); expect(loadedConfig2.routes[0].path).toEqual('LoadedModule2');
expect(module2._parent).toBe(module); expect(module2._parent).toBe(module);
@ -124,11 +125,10 @@ describe('RouterPreloader', () => {
}); });
}); });
it('should work', it('should work', fakeAsync(inject(
fakeAsync(inject(
[NgModuleFactoryLoader, RouterPreloader, Router, NgModuleRef, Compiler], [NgModuleFactoryLoader, RouterPreloader, Router, NgModuleRef, Compiler],
(loader: SpyNgModuleFactoryLoader, preloader: RouterPreloader, router: Router, (loader: SpyNgModuleFactoryLoader, preloader: RouterPreloader,
testModule: NgModuleRef<any>, compiler: Compiler) => { router: Router, testModule: NgModuleRef<any>, compiler: Compiler) => {
@NgModule() @NgModule()
class LoadedModule2 { class LoadedModule2 {
} }
@ -165,12 +165,14 @@ describe('RouterPreloader', () => {
const c = router.config; const c = router.config;
const loadedConfig: LoadedRouterConfig = c[0]._loadedConfig !; const loadedConfig: LoadedRouterConfig = (c[0] as any)._loadedConfig !;
const module: any = loadedConfig.module; const module: any = loadedConfig.module;
expect(module._parent).toBe(testModule); expect(module._parent).toBe(testModule);
const loadedConfig2: LoadedRouterConfig = loadedConfig.routes[0]._loadedConfig !; const loadedConfig2: LoadedRouterConfig =
const loadedConfig3: LoadedRouterConfig = loadedConfig2.routes[0]._loadedConfig !; (loadedConfig.routes[0] as any)._loadedConfig !;
const loadedConfig3: LoadedRouterConfig =
(loadedConfig2.routes[0] as any)._loadedConfig !;
const module3: any = loadedConfig3.module; const module3: any = loadedConfig3.module;
expect(module3._parent).toBe(module2); expect(module3._parent).toBe(module2);
}))); })));
@ -204,8 +206,8 @@ describe('RouterPreloader', () => {
tick(); tick();
const c = router.config; const c = router.config;
expect(c[0]._loadedConfig).not.toBeDefined(); expect((c[0] as any)._loadedConfig).not.toBeDefined();
expect(c[1]._loadedConfig).toBeDefined(); expect((c[1] as any)._loadedConfig).toBeDefined();
}))); })));
}); });
}); });

View File

@ -27,7 +27,7 @@ describe('RouterState & Snapshot', () => {
const root = new TreeNode(a, [new TreeNode(b, []), new TreeNode(c, [])]); const root = new TreeNode(a, [new TreeNode(b, []), new TreeNode(c, [])]);
state = new RouterStateSnapshot('url', root); state = new (RouterStateSnapshot as any)('url', root);
}); });
it('should return first child', () => { expect(state.root.firstChild).toBe(b); }); it('should return first child', () => { expect(state.root.firstChild).toBe(b); });
@ -69,7 +69,7 @@ describe('RouterState & Snapshot', () => {
const root = new TreeNode(a, [new TreeNode(b, []), new TreeNode(c, [])]); const root = new TreeNode(a, [new TreeNode(b, []), new TreeNode(c, [])]);
state = new RouterState(root, <any>null); state = new (RouterState as any)(root, <any>null);
}); });
it('should return first child', () => { expect(state.root.firstChild).toBe(b); }); it('should return first child', () => { expect(state.root.firstChild).toBe(b); });
@ -100,10 +100,10 @@ describe('RouterState & Snapshot', () => {
describe('equalParamsAndUrlSegments', () => { describe('equalParamsAndUrlSegments', () => {
function createSnapshot(params: Params, url: UrlSegment[]): ActivatedRouteSnapshot { function createSnapshot(params: Params, url: UrlSegment[]): ActivatedRouteSnapshot {
const snapshot = new ActivatedRouteSnapshot( const snapshot = new (ActivatedRouteSnapshot as any)(
url, params, <any>null, <any>null, <any>null, <any>null, <any>null, <any>null, <any>null, url, params, <any>null, <any>null, <any>null, <any>null, <any>null, <any>null, <any>null,
-1, null !); -1, null !);
snapshot._routerState = new RouterStateSnapshot('', new TreeNode(snapshot, [])); snapshot._routerState = new (RouterStateSnapshot as any)('', new TreeNode(snapshot, []));
return snapshot; return snapshot;
} }
@ -116,10 +116,10 @@ describe('RouterState & Snapshot', () => {
const snapshot1Parent = createSnapshot(parentParams[0], [new UrlSegment(urls[0], {})]); const snapshot1Parent = createSnapshot(parentParams[0], [new UrlSegment(urls[0], {})]);
const snapshot2Parent = createSnapshot(parentParams[1], [new UrlSegment(urls[1], {})]); const snapshot2Parent = createSnapshot(parentParams[1], [new UrlSegment(urls[1], {})]);
snapshot1._routerState = (snapshot1 as any)._routerState = new (RouterStateSnapshot as any)(
new RouterStateSnapshot('', new TreeNode(snapshot1Parent, [new TreeNode(snapshot1, [])])); '', new TreeNode(snapshot1Parent, [new TreeNode(snapshot1, [])]));
snapshot2._routerState = (snapshot2 as any)._routerState = new (RouterStateSnapshot as any)(
new RouterStateSnapshot('', new TreeNode(snapshot2Parent, [new TreeNode(snapshot2, [])])); '', new TreeNode(snapshot2Parent, [new TreeNode(snapshot2, [])]));
return [snapshot1, snapshot2]; return [snapshot1, snapshot2];
} }
@ -175,10 +175,10 @@ describe('RouterState & Snapshot', () => {
const queryParams = {}; const queryParams = {};
const fragment = ''; const fragment = '';
const data = {}; const data = {};
const snapshot = new ActivatedRouteSnapshot( const snapshot = new (ActivatedRouteSnapshot as any)(
url, params, queryParams, fragment, data, <any>null, <any>null, <any>null, <any>null, -1, url, params, queryParams, fragment, data, <any>null, <any>null, <any>null, <any>null, -1,
null !); null !);
const state = new RouterStateSnapshot('', new TreeNode(snapshot, [])); const state = new (RouterStateSnapshot as any)('', new TreeNode(snapshot, []));
snapshot._routerState = state; snapshot._routerState = state;
return snapshot; return snapshot;
} }
@ -187,7 +187,7 @@ describe('RouterState & Snapshot', () => {
const firstPlace = createSnapshot({a: 1}, []); const firstPlace = createSnapshot({a: 1}, []);
const secondPlace = createSnapshot({a: 2}, []); const secondPlace = createSnapshot({a: 2}, []);
route.snapshot = firstPlace; route.snapshot = firstPlace;
route._futureSnapshot = secondPlace; (route as any)._futureSnapshot = secondPlace;
let hasSeenDataChange = false; let hasSeenDataChange = false;
route.data.forEach((data) => { hasSeenDataChange = true; }); route.data.forEach((data) => { hasSeenDataChange = true; });
@ -198,13 +198,13 @@ describe('RouterState & Snapshot', () => {
}); });
function createActivatedRouteSnapshot(cmp: string) { function createActivatedRouteSnapshot(cmp: string) {
return new ActivatedRouteSnapshot( return new (ActivatedRouteSnapshot as any)(
<any>null, <any>null, <any>null, <any>null, <any>null, <any>null, <any>cmp, <any>null, <any>null, <any>null, <any>null, <any>null, <any>null, <any>null, <any>cmp, <any>null,
<any>null, -1, null !); <any>null, -1, null !);
} }
function createActivatedRoute(cmp: string) { function createActivatedRoute(cmp: string) {
return new ActivatedRoute( return new (ActivatedRoute as any)(
new BehaviorSubject([new UrlSegment('', {})]), new BehaviorSubject({}), <any>null, <any>null, new BehaviorSubject([new UrlSegment('', {})]), new BehaviorSubject({}), <any>null, <any>null,
new BehaviorSubject({}), <any>null, <any>cmp, <any>null); new BehaviorSubject({}), <any>null, <any>cmp, <any>null);
} }

View File

@ -36,7 +36,7 @@ describe('SpyNgModuleFactoryLoader', () => {
const r = new SpyNgModuleFactoryLoader(<any>null); const r = new SpyNgModuleFactoryLoader(<any>null);
let error: any = null; let error: any = null;
r.load('two').catch(e => error = e); r.load('two').catch((e: any) => error = e);
tick(); tick();

View File

@ -10,44 +10,44 @@ import {Tree, TreeNode} from '../../src/utils/tree';
describe('tree', () => { describe('tree', () => {
it('should return the root of the tree', () => { it('should return the root of the tree', () => {
const t = new Tree<any>(new TreeNode<number>(1, [])); const t = new Tree<any>(new TreeNode<number>(1, [])) as any;
expect(t.root).toEqual(1); expect(t.root).toEqual(1);
}); });
it('should return the parent of a node', () => { it('should return the parent of a node', () => {
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])])); const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])])) as any;
expect(t.parent(1)).toEqual(null); expect(t.parent(1)).toEqual(null);
expect(t.parent(2)).toEqual(1); expect(t.parent(2)).toEqual(1);
}); });
it('should return the parent of a node (second child)', () => { it('should return the parent of a node (second child)', () => {
const t = new Tree<any>( const t = new Tree<any>(
new TreeNode<number>(1, [new TreeNode<number>(2, []), new TreeNode<number>(3, [])])); new TreeNode<number>(1, [new TreeNode<number>(2, []), new TreeNode<number>(3, [])])) as any;
expect(t.parent(1)).toEqual(null); expect(t.parent(1)).toEqual(null);
expect(t.parent(3)).toEqual(1); expect(t.parent(3)).toEqual(1);
}); });
it('should return the children of a node', () => { it('should return the children of a node', () => {
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])])); const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])])) as any;
expect(t.children(1)).toEqual([2]); expect(t.children(1)).toEqual([2]);
expect(t.children(2)).toEqual([]); expect(t.children(2)).toEqual([]);
}); });
it('should return the first child of a node', () => { it('should return the first child of a node', () => {
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])])); const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])])) as any;
expect(t.firstChild(1)).toEqual(2); expect(t.firstChild(1)).toEqual(2);
expect(t.firstChild(2)).toEqual(null); expect(t.firstChild(2)).toEqual(null);
}); });
it('should return the siblings of a node', () => { it('should return the siblings of a node', () => {
const t = new Tree<any>( const t = new Tree<any>(
new TreeNode<number>(1, [new TreeNode<number>(2, []), new TreeNode<number>(3, [])])); new TreeNode<number>(1, [new TreeNode<number>(2, []), new TreeNode<number>(3, [])])) as any;
expect(t.siblings(2)).toEqual([3]); expect(t.siblings(2)).toEqual([3]);
expect(t.siblings(1)).toEqual([]); expect(t.siblings(1)).toEqual([]);
}); });
it('should return the path to the root', () => { it('should return the path to the root', () => {
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])])); const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])])) as any;
expect(t.pathFromRoot(2)).toEqual([1, 2]); expect(t.pathFromRoot(2)).toEqual([1, 2]);
}); });
}); });

View File

@ -0,0 +1,42 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
tsconfig = "//packages:tsconfig",
deps = [
"//packages:types",
"//packages/core",
"//packages/core/testing",
"//packages/service-worker",
"//packages/service-worker/testing",
"//packages/service-worker/worker",
"//packages/service-worker/worker/testing",
"@rxjs",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
deps = [
":test_lib",
"//packages/_testing_init:node",
],
)
ts_web_test(
name = "test_web",
bootstrap = [
"//:angular_bootstrap_scripts",
],
# dissable since tests are running but not yet passing
tags = ["manual"],
# do not sort
deps = [
"//packages/_testing_init:browser",
":test_lib",
],
)

View File

@ -30,14 +30,14 @@ import {MockServiceWorkerContainer, MockServiceWorkerRegistration} from '../test
mock.setupSw(); mock.setupSw();
comm.registration.subscribe(reg => { done(); }); (comm as any).registration.subscribe((reg: any) => { done(); });
}); });
it('can access the registration when it comes after subscription', (done: DoneFn) => { it('can access the registration when it comes after subscription', (done: DoneFn) => {
const mock = new MockServiceWorkerContainer(); const mock = new MockServiceWorkerContainer();
const comm = new NgswCommChannel(mock as any, 'browser'); const comm = new NgswCommChannel(mock as any, 'browser');
const regPromise = mock.getRegistration() as any as MockServiceWorkerRegistration; const regPromise = mock.getRegistration() as any as MockServiceWorkerRegistration;
comm.registration.subscribe(reg => { done(); }); (comm as any).registration.subscribe((reg: any) => { done(); });
mock.setupSw(); mock.setupSw();
}); });

View File

@ -0,0 +1,13 @@
package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
ts_library(
name = "testing",
testonly = 1,
srcs = glob(["**/*.ts"]),
module_name = "@angular/service-worker/testing",
tsconfig = "//packages:tsconfig",
deps = [
],
)

View File

@ -18,8 +18,6 @@ ts_library(
jasmine_node_test( jasmine_node_test(
name = "test", name = "test",
srcs = [], srcs = [],
# TODO(alxhub): re-enable when need for main() is removed
tags = ["manual"],
deps = [ deps = [
":test_lib", ":test_lib",
], ],

3
packages/types.d.ts vendored
View File

@ -16,3 +16,6 @@
/// <reference path="./es6-subset.d.ts" /> /// <reference path="./es6-subset.d.ts" />
/// <reference path="./system.d.ts" /> /// <reference path="./system.d.ts" />
/// <reference path="./goog.d.ts" /> /// <reference path="./goog.d.ts" />
declare let isNode: boolean;
declare let isBrowser: boolean;

View File

@ -0,0 +1,20 @@
package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
ts_library(
name = "upgrade",
srcs = glob(
[
"*.ts",
"src/**/*.ts",
],
),
module_name = "@angular/upgrade",
tsconfig = "//packages:tsconfig",
deps = [
"//packages/core",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
],
)

View File

@ -0,0 +1,35 @@
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.ts"]),
tsconfig = "//packages:tsconfig",
deps = [
"//packages:types",
"//packages/core",
"//packages/core/testing",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
"//packages/platform-browser/testing",
"//packages/upgrade",
"//packages/upgrade/static",
"@rxjs",
],
)
ts_web_test(
name = "test_web",
bootstrap = [
"//:angular_bootstrap_scripts",
"//:node_modules/angular/angular.js",
],
# dissable since tests are running but not yet passing
tags = ["manual"],
# do not sort
deps = [
"//packages/_testing_init:browser",
":test_lib",
],
)

View File

@ -14,6 +14,10 @@ import * as angular from '@angular/upgrade/src/common/angular1';
import {UpgradeAdapter, UpgradeAdapterRef} from '@angular/upgrade/src/dynamic/upgrade_adapter'; import {UpgradeAdapter, UpgradeAdapterRef} from '@angular/upgrade/src/dynamic/upgrade_adapter';
import {$digest, html, multiTrim} from './test_helpers'; import {$digest, html, multiTrim} from './test_helpers';
declare global {
export var inject: Function;
}
{ {
describe('adapter: ng1 to ng2', () => { describe('adapter: ng1 to ng2', () => {
beforeEach(() => destroyPlatform()); beforeEach(() => destroyPlatform());

View File

@ -15,6 +15,9 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 100;
// we will call `__karma__.start()` later, once all the specs are loaded. // we will call `__karma__.start()` later, once all the specs are loaded.
__karma__.loaded = function() {}; __karma__.loaded = function() {};
window.isNode = false;
window.isBrowser = true;
System.config({ System.config({
baseURL: '/base', baseURL: '/base',
defaultJSExtensions: true, defaultJSExtensions: true,

View File

@ -45,6 +45,9 @@ if (globsIndex < 0) {
args = process.argv.slice(globsIndex + 1); args = process.argv.slice(globsIndex + 1);
} }
(global as any).isNode = true;
(global as any).isBrowser = false;
var specFiles: any = var specFiles: any =
args.map(function(globstr: string): args.map(function(globstr: string):
string[] { string[] {