build: reformat repo to new clang@1.4.0 (#36628)

PR Close #36628
This commit is contained in:
Joey Perrott
2020-04-13 17:43:52 -07:00
committed by atscott
parent 4b3f9ac739
commit 26f49151e7
1163 changed files with 31727 additions and 24036 deletions

View File

@ -41,7 +41,9 @@ export function asyncFallback(fn: Function): (done: any) => any {
// if we run beforeEach in @angular/core/testing/testing_internal then we get no done
// fake it here and assume sync.
done = function() {};
done.fail = function(e: any) { throw e; };
done.fail = function(e: any) {
throw e;
};
}
runInTestZone(fn, this, done, (err: any) => {
if (typeof err === 'string') {
@ -87,7 +89,7 @@ function runInTestZone(
// If we do it in ProxyZone then we will get to infinite recursion.
const proxyZone = Zone.current.getZoneWith('ProxyZoneSpec');
const previousDelegate = proxyZoneSpec.getDelegate();
proxyZone !.parent !.run(() => {
proxyZone!.parent!.run(() => {
const testZoneSpec: ZoneSpec = new AsyncTestZoneSpec(
() => {
// Need to restore the original zone.

View File

@ -11,16 +11,22 @@
*/
export class AsyncTestCompleter {
// TODO(issue/24571): remove '!'.
private _resolve !: (result: any) => void;
private _resolve!: (result: any) => void;
// TODO(issue/24571): remove '!'.
private _reject !: (err: any) => void;
private _reject!: (err: any) => void;
private _promise: Promise<any> = new Promise((res, rej) => {
this._resolve = res;
this._reject = rej;
});
done(value?: any) { this._resolve(value); }
done(value?: any) {
this._resolve(value);
}
fail(error?: any, stackTrace?: string) { this._reject(error); }
fail(error?: any, stackTrace?: string) {
this._reject(error);
}
get promise(): Promise<any> { return this._promise; }
get promise(): Promise<any> {
return this._promise;
}
}

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ChangeDetectorRef, ComponentRef, DebugElement, ElementRef, NgZone, RendererFactory2, getDebugNode} from '@angular/core';
import {ChangeDetectorRef, ComponentRef, DebugElement, ElementRef, getDebugNode, NgZone, RendererFactory2} from '@angular/core';
/**
@ -65,8 +65,11 @@ export class ComponentFixture<T> {
// Create subscriptions outside the NgZone so that the callbacks run oustide
// of NgZone.
ngZone.runOutsideAngular(() => {
this._onUnstableSubscription =
ngZone.onUnstable.subscribe({next: () => { this._isStable = false; }});
this._onUnstableSubscription = ngZone.onUnstable.subscribe({
next: () => {
this._isStable = false;
}
});
this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
next: () => {
if (this._autoDetect) {
@ -87,7 +90,7 @@ export class ComponentFixture<T> {
scheduleMicroTask(() => {
if (!ngZone.hasPendingMacrotasks) {
if (this._promise !== null) {
this._resolve !(true);
this._resolve!(true);
this._resolve = null;
this._promise = null;
}
@ -97,8 +100,11 @@ export class ComponentFixture<T> {
}
});
this._onErrorSubscription =
ngZone.onError.subscribe({next: (error: any) => { throw error; }});
this._onErrorSubscription = ngZone.onError.subscribe({
next: (error: any) => {
throw error;
}
});
});
}
}
@ -117,7 +123,9 @@ export class ComponentFixture<T> {
if (this.ngZone != null) {
// Run the change detection inside the NgZone so that any async tasks as part of the change
// detection are captured by the zone and can be waited for in isStable.
this.ngZone.run(() => { this._tick(checkNoChanges); });
this.ngZone.run(() => {
this._tick(checkNoChanges);
});
} else {
// Running without zone. Just do the change detection.
this._tick(checkNoChanges);
@ -127,7 +135,9 @@ export class ComponentFixture<T> {
/**
* Do a change detection run to make sure there were no changes.
*/
checkNoChanges(): void { this.changeDetectorRef.checkNoChanges(); }
checkNoChanges(): void {
this.changeDetectorRef.checkNoChanges();
}
/**
* Set whether the fixture should autodetect changes.
@ -146,7 +156,9 @@ export class ComponentFixture<T> {
* Return whether the fixture is currently stable or has async tasks that have not been completed
* yet.
*/
isStable(): boolean { return this._isStable && !this.ngZone !.hasPendingMacrotasks; }
isStable(): boolean {
return this._isStable && !this.ngZone!.hasPendingMacrotasks;
}
/**
* Get a promise that resolves when the fixture is stable.
@ -160,7 +172,9 @@ export class ComponentFixture<T> {
} else if (this._promise !== null) {
return this._promise;
} else {
this._promise = new Promise(res => { this._resolve = res; });
this._promise = new Promise(res => {
this._resolve = res;
});
return this._promise;
}
}
@ -174,8 +188,8 @@ export class ComponentFixture<T> {
}
/**
* Get a promise that resolves when the ui state is stable following animations.
*/
* Get a promise that resolves when the ui state is stable following animations.
*/
whenRenderingDone(): Promise<any> {
const renderer = this._getRenderer();
if (renderer && renderer.whenRenderingDone) {

View File

@ -12,9 +12,13 @@ import {Injectable} from '@angular/core';
export class Log {
logItems: any[];
constructor() { this.logItems = []; }
constructor() {
this.logItems = [];
}
add(value: any /** TODO #9100 */): void { this.logItems.push(value); }
add(value: any /** TODO #9100 */): void {
this.logItems.push(value);
}
fn(value: any /** TODO #9100 */) {
return (a1: any = null, a2: any = null, a3: any = null, a4: any = null, a5: any = null) => {
@ -22,7 +26,11 @@ export class Log {
};
}
clear(): void { this.logItems = []; }
clear(): void {
this.logItems = [];
}
result(): string { return this.logItems.join('; '); }
result(): string {
return this.logItems.join('; ');
}
}

View File

@ -22,7 +22,7 @@ export class MetadataOverrider {
* based on an old instance and overrides.
*/
overrideMetadata<C extends T, T>(
metadataClass: {new (options: T): C;}, oldMetadata: C, override: MetadataOverride<T>): C {
metadataClass: {new(options: T): C;}, oldMetadata: C, override: MetadataOverride<T>): C {
const props: StringMap = {};
if (oldMetadata) {
_valueProps(oldMetadata).forEach((prop) => props[prop] = (<any>oldMetadata)[prop]);
@ -49,8 +49,9 @@ function removeMetadata(metadata: StringMap, remove: any, references: Map<any, s
for (const prop in remove) {
const removeValue = remove[prop];
if (Array.isArray(removeValue)) {
removeValue.forEach(
(value: any) => { removeObjects.add(_propHashKey(prop, value, references)); });
removeValue.forEach((value: any) => {
removeObjects.add(_propHashKey(prop, value, references));
});
} else {
removeObjects.add(_propHashKey(prop, removeValue, references));
}

View File

@ -16,11 +16,19 @@ import {EventEmitter, Injectable, NgZone} from '@angular/core';
export class MockNgZone extends NgZone {
onStable: EventEmitter<any> = new EventEmitter(false);
constructor() { super({enableLongStackTrace: false, shouldCoalesceEventChangeDetection: false}); }
constructor() {
super({enableLongStackTrace: false, shouldCoalesceEventChangeDetection: false});
}
run(fn: Function): any { return fn(); }
run(fn: Function): any {
return fn();
}
runOutsideAngular(fn: Function): any { return fn(); }
runOutsideAngular(fn: Function): any {
return fn();
}
simulateZoneExit(): void { this.onStable.emit(null); }
simulateZoneExit(): void {
this.onStable.emit(null);
}
}

View File

@ -9,7 +9,8 @@
// The formatter and CI disagree on how this import statement should be formatted. Both try to keep
// it on one line, too, which has gotten very hard to read & manage. So disable the formatter for
// this statement only.
// clang-format off
/* clang-format off */
import {
AbstractType,
Component,
@ -22,23 +23,25 @@ import {
Pipe,
PlatformRef,
Type,
ɵflushModuleScopingQueueAsMuchAsPossible as flushModuleScopingQueueAsMuchAsPossible,
ɵRender3ComponentFactory as ComponentFactory,
ɵRender3NgModuleRef as NgModuleRef,
ɵflushModuleScopingQueueAsMuchAsPossible as flushModuleScopingQueueAsMuchAsPossible,
ɵresetCompiledComponents as resetCompiledComponents,
ɵstringify as stringify,
} from '@angular/core';
// clang-format on
/* clang-format on */
import {ComponentFixture} from './component_fixture';
import {MetadataOverride} from './metadata_override';
import {R3TestBedCompiler} from './r3_test_bed_compiler';
import {TestBed} from './test_bed';
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestBedStatic, TestComponentRenderer, TestModuleMetadata} from './test_bed_common';
import {R3TestBedCompiler} from './r3_test_bed_compiler';
let _nextRootElementId = 0;
/**
* @description
* Configures and initializes environment for unit testing and provides methods for
@ -75,7 +78,9 @@ export class TestBedRender3 implements TestBed {
*
* @publicApi
*/
static resetTestEnvironment(): void { _getTestBedRender3().resetTestEnvironment(); }
static resetTestEnvironment(): void {
_getTestBedRender3().resetTestEnvironment();
}
static configureCompiler(config: {providers?: any[]; useJit?: boolean;}): TestBedStatic {
_getTestBedRender3().configureCompiler(config);
@ -96,7 +101,9 @@ export class TestBedRender3 implements TestBed {
* It is necessary to call this function
* as fetching urls is asynchronous.
*/
static compileComponents(): Promise<any> { return _getTestBedRender3().compileComponents(); }
static compileComponents(): Promise<any> {
return _getTestBedRender3().compileComponents();
}
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic {
_getTestBedRender3().overrideModule(ngModule, override);
@ -121,7 +128,7 @@ export class TestBedRender3 implements TestBed {
}
static overrideTemplate(component: Type<any>, template: string): TestBedStatic {
_getTestBedRender3().overrideComponent(component, {set: {template, templateUrl: null !}});
_getTestBedRender3().overrideComponent(component, {set: {template, templateUrl: null!}});
return TestBedRender3 as any as TestBedStatic;
}
@ -183,8 +190,8 @@ export class TestBedRender3 implements TestBed {
// Properties
platform: PlatformRef = null !;
ngModule: Type<any>|Type<any>[] = null !;
platform: PlatformRef = null!;
ngModule: Type<any>|Type<any>[] = null!;
private _compiler: R3TestBedCompiler|null = null;
private _testModuleRef: NgModuleRef<any>|null = null;
@ -223,8 +230,8 @@ export class TestBedRender3 implements TestBed {
resetTestEnvironment(): void {
this.resetTestingModule();
this._compiler = null;
this.platform = null !;
this.ngModule = null !;
this.platform = null!;
this.ngModule = null!;
}
resetTestingModule(): void {
@ -253,7 +260,9 @@ export class TestBedRender3 implements TestBed {
this.compiler.configureTestingModule(moduleDef);
}
compileComponents(): Promise<any> { return this.compiler.compileComponents(); }
compileComponents(): Promise<any> {
return this.compiler.compileComponents();
}
inject<T>(
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;

View File

@ -7,7 +7,7 @@
*/
import {ResourceLoader} from '@angular/compiler';
import {ApplicationInitStatus, COMPILER_OPTIONS, Compiler, Component, Directive, Injector, InjectorType, LOCALE_ID, ModuleWithComponentFactories, ModuleWithProviders, NgModule, NgModuleFactory, NgZone, Pipe, PlatformRef, Provider, Type, ɵDEFAULT_LOCALE_ID as DEFAULT_LOCALE_ID, ɵDirectiveDef as DirectiveDef, ɵNG_COMP_DEF as NG_COMP_DEF, ɵNG_DIR_DEF as NG_DIR_DEF, ɵNG_INJ_DEF as NG_INJ_DEF, ɵNG_MOD_DEF as NG_MOD_DEF, ɵNG_PIPE_DEF as NG_PIPE_DEF, ɵNgModuleFactory as R3NgModuleFactory, ɵNgModuleTransitiveScopes as NgModuleTransitiveScopes, ɵNgModuleType as NgModuleType, ɵRender3ComponentFactory as ComponentFactory, ɵRender3NgModuleRef as NgModuleRef, ɵcompileComponent as compileComponent, ɵcompileDirective as compileDirective, ɵcompileNgModuleDefs as compileNgModuleDefs, ɵcompilePipe as compilePipe, ɵgetInjectableDef as getInjectableDef, ɵpatchComponentDefWithScope as patchComponentDefWithScope, ɵsetLocaleId as setLocaleId, ɵtransitiveScopesFor as transitiveScopesFor, ɵɵInjectableDef as InjectableDef} from '@angular/core';
import {ApplicationInitStatus, Compiler, COMPILER_OPTIONS, Component, Directive, Injector, InjectorType, LOCALE_ID, ModuleWithComponentFactories, ModuleWithProviders, NgModule, NgModuleFactory, NgZone, Pipe, PlatformRef, Provider, Type, ɵcompileComponent as compileComponent, ɵcompileDirective as compileDirective, ɵcompileNgModuleDefs as compileNgModuleDefs, ɵcompilePipe as compilePipe, ɵDEFAULT_LOCALE_ID as DEFAULT_LOCALE_ID, ɵDirectiveDef as DirectiveDef, ɵgetInjectableDef as getInjectableDef, ɵNG_COMP_DEF as NG_COMP_DEF, ɵNG_DIR_DEF as NG_DIR_DEF, ɵNG_INJ_DEF as NG_INJ_DEF, ɵNG_MOD_DEF as NG_MOD_DEF, ɵNG_PIPE_DEF as NG_PIPE_DEF, ɵNgModuleFactory as R3NgModuleFactory, ɵNgModuleTransitiveScopes as NgModuleTransitiveScopes, ɵNgModuleType as NgModuleType, ɵpatchComponentDefWithScope as patchComponentDefWithScope, ɵRender3ComponentFactory as ComponentFactory, ɵRender3NgModuleRef as NgModuleRef, ɵsetLocaleId as setLocaleId, ɵtransitiveScopesFor as transitiveScopesFor, ɵɵInjectableDef as InjectableDef} from '@angular/core';
import {clearResolutionOfComponentResourcesQueue, isComponentDefPendingResolution, resolveComponentResources, restoreComponentResolutionQueue} from '../../src/metadata/resource_loading';
@ -194,7 +194,7 @@ export class R3TestBedCompiler {
overrideTemplateUsingTestingModule(type: Type<any>, template: string): void {
const def = (type as any)[NG_COMP_DEF];
const hasStyleUrls = (): boolean => {
const metadata = this.resolvers.component.resolve(type) !as Component;
const metadata = this.resolvers.component.resolve(type)! as Component;
return !!metadata.styleUrls && metadata.styleUrls.length > 0;
};
const overrideStyleUrls = !!def && !isComponentDefPendingResolution(type) && hasStyleUrls();
@ -295,7 +295,9 @@ export class R3TestBedCompiler {
/**
* @internal
*/
_getModuleResolver(): Resolver<NgModule> { return this.resolvers.module; }
_getModuleResolver(): Resolver<NgModule> {
return this.resolvers.module;
}
/**
* @internal
@ -303,7 +305,7 @@ export class R3TestBedCompiler {
_getComponentFactories(moduleType: NgModuleType): ComponentFactory<any>[] {
return maybeUnwrapFn(moduleType.ɵmod.declarations).reduce((factories, declaration) => {
const componentDef = (declaration as any).ɵcmp;
componentDef && factories.push(new ComponentFactory(componentDef, this.testModuleRef !));
componentDef && factories.push(new ComponentFactory(componentDef, this.testModuleRef!));
return factories;
}, [] as ComponentFactory<any>[]);
}
@ -348,7 +350,7 @@ export class R3TestBedCompiler {
private applyTransitiveScopes(): void {
const moduleToScope = new Map<Type<any>|TestingModuleOverride, NgModuleTransitiveScopes>();
const getScopeOfModule =
(moduleType: Type<any>| TestingModuleOverride): NgModuleTransitiveScopes => {
(moduleType: Type<any>|TestingModuleOverride): NgModuleTransitiveScopes => {
if (!moduleToScope.has(moduleType)) {
const isTestingModule = isTestingModuleOverride(moduleType);
const realType = isTestingModule ? this.testModuleType : moduleType as Type<any>;
@ -363,7 +365,7 @@ export class R3TestBedCompiler {
}
moduleToScope.set(moduleType, transitiveScopesFor(realType));
}
return moduleToScope.get(moduleType) !;
return moduleToScope.get(moduleType)!;
};
this.componentToModuleScope.forEach((moduleType, componentType) => {
@ -379,7 +381,7 @@ export class R3TestBedCompiler {
private applyProviderOverrides(): void {
const maybeApplyOverrides = (field: string) => (type: Type<any>) => {
const resolver = field === NG_COMP_DEF ? this.resolvers.component : this.resolvers.directive;
const metadata = resolver.resolve(type) !;
const metadata = resolver.resolve(type)!;
if (this.hasProviderOverrides(metadata.providers)) {
this.patchDefWithProviderOverrides(type, field);
}
@ -553,7 +555,7 @@ export class R3TestBedCompiler {
this.originalComponentResolutionQueue = new Map();
}
clearResolutionOfComponentResourcesQueue().forEach(
(value, key) => this.originalComponentResolutionQueue !.set(key, value));
(value, key) => this.originalComponentResolutionQueue!.set(key, value));
}
/*
@ -575,21 +577,20 @@ export class R3TestBedCompiler {
op.object[op.fieldName] = op.originalValue;
});
// Restore initial component/directive/pipe defs
this.initialNgDefs.forEach(
(value: [string, PropertyDescriptor | undefined], type: Type<any>) => {
const [prop, descriptor] = value;
if (!descriptor) {
// Delete operations are generally undesirable since they have performance implications
// on objects they were applied to. In this particular case, situations where this code
// is invoked should be quite rare to cause any noticeable impact, since it's applied
// only to some test cases (for example when class with no annotations extends some
// @Component) when we need to clear 'ɵcmp' field on a given class to restore
// its original state (before applying overrides and running tests).
delete (type as any)[prop];
} else {
Object.defineProperty(type, prop, descriptor);
}
});
this.initialNgDefs.forEach((value: [string, PropertyDescriptor|undefined], type: Type<any>) => {
const [prop, descriptor] = value;
if (!descriptor) {
// Delete operations are generally undesirable since they have performance implications
// on objects they were applied to. In this particular case, situations where this code
// is invoked should be quite rare to cause any noticeable impact, since it's applied
// only to some test cases (for example when class with no annotations extends some
// @Component) when we need to clear 'ɵcmp' field on a given class to restore
// its original state (before applying overrides and running tests).
delete (type as any)[prop];
} else {
Object.defineProperty(type, prop, descriptor);
}
});
this.initialNgDefs.clear();
this.moduleProvidersOverridden.clear();
this.restoreComponentResolutionQueue();
@ -726,7 +727,7 @@ function hasNgModuleDef<T>(value: Type<T>): value is NgModuleType<T> {
return value.hasOwnProperty('ɵmod');
}
function maybeUnwrapFn<T>(maybeFn: (() => T) | T): T {
function maybeUnwrapFn<T>(maybeFn: (() => T)|T): T {
return maybeFn instanceof Function ? maybeFn() : maybeFn;
}

View File

@ -40,7 +40,9 @@ abstract class OverrideResolver<T> implements Resolver<T> {
setOverrides(overrides: Array<[Type<any>, MetadataOverride<T>]>) {
this.overrides.clear();
overrides.forEach(([type, override]) => { this.addOverride(type, override); });
overrides.forEach(([type, override]) => {
this.addOverride(type, override);
});
}
getAnnotation(type: Type<any>): T|null {
@ -71,7 +73,7 @@ abstract class OverrideResolver<T> implements Resolver<T> {
if (overrides) {
const overrider = new MetadataOverrider();
overrides.forEach(override => {
resolved = overrider.overrideMetadata(this.type, resolved !, override);
resolved = overrider.overrideMetadata(this.type, resolved!, override);
});
}
}
@ -84,17 +86,25 @@ abstract class OverrideResolver<T> implements Resolver<T> {
export class DirectiveResolver extends OverrideResolver<Directive> {
get type() { return Directive; }
get type() {
return Directive;
}
}
export class ComponentResolver extends OverrideResolver<Component> {
get type() { return Component; }
get type() {
return Component;
}
}
export class PipeResolver extends OverrideResolver<Pipe> {
get type() { return Pipe; }
get type() {
return Pipe;
}
}
export class NgModuleResolver extends OverrideResolver<NgModule> {
get type() { return NgModule; }
get type() {
return NgModule;
}
}

View File

@ -7,11 +7,11 @@
*/
/**
* Returns element classes in form of a stable (sorted) string.
*
* @param element HTML Element.
* @returns Returns element classes in form of a stable (sorted) string.
*/
* Returns element classes in form of a stable (sorted) string.
*
* @param element HTML Element.
* @returns Returns element classes in form of a stable (sorted) string.
*/
export function getSortedClassName(element: Element): string {
const names: string[] = Object.keys(getElementClasses(element));
names.sort();

View File

@ -6,12 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AbstractType, ApplicationInitStatus, CompilerOptions, Component, Directive, InjectFlags, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, NgZone, Optional, Pipe, PlatformRef, Provider, SchemaMetadata, SkipSelf, StaticProvider, Type, ɵDepFlags as DepFlags, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵNodeFlags as NodeFlags, ɵclearOverrides as clearOverrides, ɵgetInjectableDef as getInjectableDef, ɵivyEnabled as ivyEnabled, ɵoverrideComponentView as overrideComponentView, ɵoverrideProvider as overrideProvider, ɵstringify as stringify, ɵɵInjectableDef} from '@angular/core';
import {AbstractType, ApplicationInitStatus, CompilerOptions, Component, Directive, InjectFlags, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, NgZone, Optional, Pipe, PlatformRef, Provider, SchemaMetadata, SkipSelf, StaticProvider, Type, ɵclearOverrides as clearOverrides, ɵDepFlags as DepFlags, ɵgetInjectableDef as getInjectableDef, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵivyEnabled as ivyEnabled, ɵNodeFlags as NodeFlags, ɵoverrideComponentView as overrideComponentView, ɵoverrideProvider as overrideProvider, ɵstringify as stringify, ɵɵInjectableDef} from '@angular/core';
import {AsyncTestCompleter} from './async_test_completer';
import {ComponentFixture} from './component_fixture';
import {MetadataOverride} from './metadata_override';
import {TestBedRender3, _getTestBedRender3} from './r3_test_bed';
import {_getTestBedRender3, TestBedRender3} from './r3_test_bed';
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestBedStatic, TestComponentRenderer, TestModuleMetadata} from './test_bed_common';
import {TestingCompiler, TestingCompilerFactory} from './test_compiler';
@ -123,7 +123,9 @@ export class TestBedViewEngine implements TestBed {
/**
* Reset the providers for the test injector.
*/
static resetTestEnvironment(): void { _getTestBedViewEngine().resetTestEnvironment(); }
static resetTestEnvironment(): void {
_getTestBedViewEngine().resetTestEnvironment();
}
static resetTestingModule(): TestBedStatic {
_getTestBedViewEngine().resetTestingModule();
@ -153,7 +155,9 @@ export class TestBedViewEngine implements TestBed {
* It is necessary to call this function
* as fetching urls is asynchronous.
*/
static compileComponents(): Promise<any> { return getTestBed().compileComponents(); }
static compileComponents(): Promise<any> {
return getTestBed().compileComponents();
}
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic {
_getTestBedViewEngine().overrideModule(ngModule, override);
@ -178,7 +182,7 @@ export class TestBedViewEngine implements TestBed {
}
static overrideTemplate(component: Type<any>, template: string): TestBedStatic {
_getTestBedViewEngine().overrideComponent(component, {set: {template, templateUrl: null !}});
_getTestBedViewEngine().overrideComponent(component, {set: {template, templateUrl: null!}});
return TestBedViewEngine as any as TestBedStatic;
}
@ -243,9 +247,9 @@ export class TestBedViewEngine implements TestBed {
private _instantiated: boolean = false;
private _compiler: TestingCompiler = null !;
private _moduleRef: NgModuleRef<any> = null !;
private _moduleFactory: NgModuleFactory<any> = null !;
private _compiler: TestingCompiler = null!;
private _moduleRef: NgModuleRef<any> = null!;
private _moduleFactory: NgModuleFactory<any> = null!;
private _compilerOptions: CompilerOptions[] = [];
@ -267,9 +271,9 @@ export class TestBedViewEngine implements TestBed {
private _isRoot: boolean = true;
private _rootProviderOverrides: Provider[] = [];
platform: PlatformRef = null !;
platform: PlatformRef = null!;
ngModule: Type<any>|Type<any>[] = null !;
ngModule: Type<any>|Type<any>[] = null!;
/**
* Initialize the environment for testing with a compiler factory, a PlatformRef, and an
@ -299,8 +303,8 @@ export class TestBedViewEngine implements TestBed {
*/
resetTestEnvironment(): void {
this.resetTestingModule();
this.platform = null !;
this.ngModule = null !;
this.platform = null!;
this.ngModule = null!;
this._testEnvAotSummaries = () => [];
}
@ -308,7 +312,7 @@ export class TestBedViewEngine implements TestBed {
clearOverrides();
this._aotSummaries = [];
this._templateOverrides = [];
this._compiler = null !;
this._compiler = null!;
this._moduleOverrides = [];
this._componentOverrides = [];
this._directiveOverrides = [];
@ -317,8 +321,8 @@ export class TestBedViewEngine implements TestBed {
this._isRoot = true;
this._rootProviderOverrides = [];
this._moduleRef = null !;
this._moduleFactory = null !;
this._moduleRef = null!;
this._moduleFactory = null!;
this._compilerOptions = [];
this._providers = [];
this._declarations = [];
@ -387,7 +391,9 @@ export class TestBedViewEngine implements TestBed {
const errorCompType = this._compiler.getComponentFromError(e);
if (errorCompType) {
throw new Error(
`This test module uses the component ${stringify(errorCompType)} which is using a "templateUrl" or "styleUrls", but they were never compiled. ` +
`This test module uses the component ${
stringify(
errorCompType)} which is using a "templateUrl" or "styleUrls", but they were never compiled. ` +
`Please call "TestBed.compileComponents" before your test.`);
} else {
throw e;
@ -593,8 +599,8 @@ export class TestBedViewEngine implements TestBed {
const componentFactory = this._compiler.getComponentFactory(component);
if (!componentFactory) {
throw new Error(
`Cannot create the component ${stringify(component)} as it was not imported into the testing module!`);
throw new Error(`Cannot create the component ${
stringify(component)} as it was not imported into the testing module!`);
}
// TODO: Don't cast as `InjectionToken<boolean>`, declared type is boolean[]
@ -688,7 +694,9 @@ export function inject(tokens: any[], fn: Function): () => any {
};
} else {
// Not using an arrow function to preserve context passed from call site
return function(this: unknown) { return testBed.execute(tokens, fn, this); };
return function(this: unknown) {
return testBed.execute(tokens, fn, this);
};
}
}
@ -720,7 +728,7 @@ export class InjectSetupWrapper {
*/
export function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper;
export function withModule(moduleDef: TestModuleMetadata, fn: Function): () => any;
export function withModule(moduleDef: TestModuleMetadata, fn?: Function | null): (() => any)|
export function withModule(moduleDef: TestModuleMetadata, fn?: Function|null): (() => any)|
InjectSetupWrapper {
if (fn) {
// Not using an arrow function to preserve context passed from call site

View File

@ -49,7 +49,7 @@ export type TestModuleMetadata = {
* @publicApi
*/
export interface TestBedStatic {
new (...args: any[]): TestBed;
new(...args: any[]): TestBed;
initTestEnvironment(
ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed;

View File

@ -21,7 +21,9 @@ function unimplemented(): any {
*/
@Injectable()
export class TestingCompiler extends Compiler {
get injector(): Injector { throw unimplemented(); }
get injector(): Injector {
throw unimplemented();
}
overrideModule(module: Type<any>, overrides: MetadataOverride<NgModule>): void {
throw unimplemented();
}
@ -38,20 +40,26 @@ export class TestingCompiler extends Compiler {
* Allows to pass the compile summary from AOT compilation to the JIT compiler,
* so that it can use the code generated by AOT.
*/
loadAotSummaries(summaries: () => any[]) { throw unimplemented(); }
loadAotSummaries(summaries: () => any[]) {
throw unimplemented();
}
/**
* Gets the component factory for the given component.
* This assumes that the component has been compiled before calling this call using
* `compileModuleAndAllComponents*`.
*/
getComponentFactory<T>(component: Type<T>): ComponentFactory<T> { throw unimplemented(); }
getComponentFactory<T>(component: Type<T>): ComponentFactory<T> {
throw unimplemented();
}
/**
* Returns the component type that is stored in the given error.
* This can be used for errors created by compileModule...
*/
getComponentFromError(error: Error): Type<any>|null { throw unimplemented(); }
getComponentFromError(error: Error): Type<any>|null {
throw unimplemented();
}
}
/**

View File

@ -39,7 +39,7 @@ const globalTimeOut = jasmine.DEFAULT_TIMEOUT_INTERVAL;
const testBed = getTestBed();
export type TestFn = ((done: DoneFn) => any) | (() => any);
export type TestFn = ((done: DoneFn) => any)|(() => any);
/**
* Mechanism to run `beforeEach()` functions of Angular tests.
@ -51,20 +51,26 @@ class BeforeEachRunner {
constructor(private _parent: BeforeEachRunner) {}
beforeEach(fn: Function): void { this._fns.push(fn); }
beforeEach(fn: Function): void {
this._fns.push(fn);
}
run(): void {
if (this._parent) this._parent.run();
this._fns.forEach((fn) => { fn(); });
this._fns.forEach((fn) => {
fn();
});
}
}
// Reset the test providers before each test
jsmBeforeEach(() => { testBed.resetTestingModule(); });
jsmBeforeEach(() => {
testBed.resetTestingModule();
});
function _describe(jsmFn: Function, ...args: any[]) {
const parentRunner = runnerStack.length === 0 ? null : runnerStack[runnerStack.length - 1];
const runner = new BeforeEachRunner(parentRunner !);
const runner = new BeforeEachRunner(parentRunner!);
runnerStack.push(runner);
const suite = jsmFn(...args);
runnerStack.pop();
@ -138,7 +144,7 @@ function _it(jsmFn: Function, testName: string, testFn: TestFn, testTimeout = 0)
if (testFn.length === 0) {
// TypeScript doesn't infer the TestFn type without parameters here, so we
// need to manually cast it.
const retVal = (testFn as() => any)();
const retVal = (testFn as () => any)();
if (isPromise(retVal)) {
// Asynchronous test function that returns a Promise - wait for completion.
retVal.then(done, done.fail);
@ -192,7 +198,9 @@ export class SpyObject {
return (this as any)[name];
}
prop(name: string, value: any) { (this as any)[name] = value; }
prop(name: string, value: any) {
(this as any)[name] = value;
}
static stub(object: any = null, config: any = null, overrides: any = null) {
if (!(object instanceof SpyObject)) {
@ -202,7 +210,9 @@ export class SpyObject {
}
const m = {...config, ...overrides};
Object.keys(m).forEach(key => { object.spy(key).and.returnValue(m[key]); });
Object.keys(m).forEach(key => {
object.spy(key).and.returnValue(m[key]);
});
return object;
}
}