1
|
/**
|
2
|
* @license
|
3
|
* Copyright Google Inc. All Rights Reserved.
|
4
|
*
|
5
|
* Use of this source code is governed by an MIT-style license that can be
|
6
|
* found in the LICENSE file at https://angular.io/license
|
7
|
*/
|
8
|
import { Component, Directive, InjectionToken, Injector, NgModule, Pipe, PlatformRef, SchemaMetadata, Type } from '@angular/core';
|
9
|
import { ComponentFixture } from './component_fixture';
|
10
|
import { MetadataOverride } from './metadata_override';
|
11
|
/**
|
12
|
* An abstract class for inserting the root test component element in a platform independent way.
|
13
|
*
|
14
|
* @experimental
|
15
|
*/
|
16
|
export declare class TestComponentRenderer {
|
17
|
insertRootElement(rootElementId: string): void;
|
18
|
}
|
19
|
/**
|
20
|
* @experimental
|
21
|
*/
|
22
|
export declare const ComponentFixtureAutoDetect: InjectionToken<boolean[]>;
|
23
|
/**
|
24
|
* @experimental
|
25
|
*/
|
26
|
export declare const ComponentFixtureNoNgZone: InjectionToken<boolean[]>;
|
27
|
/**
|
28
|
* @experimental
|
29
|
*/
|
30
|
export declare type TestModuleMetadata = {
|
31
|
providers?: any[];
|
32
|
declarations?: any[];
|
33
|
imports?: any[];
|
34
|
schemas?: Array<SchemaMetadata | any[]>;
|
35
|
};
|
36
|
/**
|
37
|
* @whatItDoes Configures and initializes environment for unit testing and provides methods for
|
38
|
* creating components and services in unit tests.
|
39
|
* @description
|
40
|
*
|
41
|
* TestBed is the primary api for writing unit tests for Angular applications and libraries.
|
42
|
*
|
43
|
* @stable
|
44
|
*/
|
45
|
export declare class TestBed implements Injector {
|
46
|
/**
|
47
|
* Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
48
|
* angular module. These are common to every test in the suite.
|
49
|
*
|
50
|
* This may only be called once, to set up the common providers for the current test
|
51
|
* suite on the current platform. If you absolutely need to change the providers,
|
52
|
* first use `resetTestEnvironment`.
|
53
|
*
|
54
|
* Test modules and platforms for individual platforms are available from
|
55
|
* '@angular/<platform_name>/testing'.
|
56
|
*
|
57
|
* @experimental
|
58
|
*/
|
59
|
static initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed;
|
60
|
/**
|
61
|
* Reset the providers for the test injector.
|
62
|
*
|
63
|
* @experimental
|
64
|
*/
|
65
|
static resetTestEnvironment(): void;
|
66
|
static resetTestingModule(): typeof TestBed;
|
67
|
/**
|
68
|
* Allows overriding default compiler providers and settings
|
69
|
* which are defined in test_injector.js
|
70
|
*/
|
71
|
static configureCompiler(config: {
|
72
|
providers?: any[];
|
73
|
useJit?: boolean;
|
74
|
}): typeof TestBed;
|
75
|
/**
|
76
|
* Allows overriding default providers, directives, pipes, modules of the test injector,
|
77
|
* which are defined in test_injector.js
|
78
|
*/
|
79
|
static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed;
|
80
|
/**
|
81
|
* Compile components with a `templateUrl` for the test's NgModule.
|
82
|
* It is necessary to call this function
|
83
|
* as fetching urls is asynchronous.
|
84
|
*/
|
85
|
static compileComponents(): Promise<any>;
|
86
|
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): typeof TestBed;
|
87
|
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): typeof TestBed;
|
88
|
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): typeof TestBed;
|
89
|
static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): typeof TestBed;
|
90
|
static overrideTemplate(component: Type<any>, template: string): typeof TestBed;
|
91
|
/**
|
92
|
* Overwrites all providers for the given token with the given provider definition.
|
93
|
*/
|
94
|
static overrideProvider(token: any, provider: {
|
95
|
useFactory: Function;
|
96
|
deps: any[];
|
97
|
}): void;
|
98
|
static overrideProvider(token: any, provider: {
|
99
|
useValue: any;
|
100
|
}): void;
|
101
|
/**
|
102
|
* Overwrites all providers for the given token with the given provider definition.
|
103
|
*
|
104
|
* @deprecated as it makes all NgModules lazy. Introduced only for migrating off of it.
|
105
|
*/
|
106
|
static deprecatedOverrideProvider(token: any, provider: {
|
107
|
useFactory: Function;
|
108
|
deps: any[];
|
109
|
}): void;
|
110
|
static deprecatedOverrideProvider(token: any, provider: {
|
111
|
useValue: any;
|
112
|
}): void;
|
113
|
static get(token: any, notFoundValue?: any): any;
|
114
|
static createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
115
|
private _instantiated;
|
116
|
private _compiler;
|
117
|
private _moduleRef;
|
118
|
private _moduleFactory;
|
119
|
private _compilerOptions;
|
120
|
private _moduleOverrides;
|
121
|
private _componentOverrides;
|
122
|
private _directiveOverrides;
|
123
|
private _pipeOverrides;
|
124
|
private _providers;
|
125
|
private _declarations;
|
126
|
private _imports;
|
127
|
private _schemas;
|
128
|
private _activeFixtures;
|
129
|
private _aotSummaries;
|
130
|
platform: PlatformRef;
|
131
|
ngModule: Type<any> | Type<any>[];
|
132
|
/**
|
133
|
* Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
134
|
* angular module. These are common to every test in the suite.
|
135
|
*
|
136
|
* This may only be called once, to set up the common providers for the current test
|
137
|
* suite on the current platform. If you absolutely need to change the providers,
|
138
|
* first use `resetTestEnvironment`.
|
139
|
*
|
140
|
* Test modules and platforms for individual platforms are available from
|
141
|
* '@angular/<platform_name>/testing'.
|
142
|
*
|
143
|
* @experimental
|
144
|
*/
|
145
|
initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void;
|
146
|
/**
|
147
|
* Reset the providers for the test injector.
|
148
|
*
|
149
|
* @experimental
|
150
|
*/
|
151
|
resetTestEnvironment(): void;
|
152
|
resetTestingModule(): void;
|
153
|
configureCompiler(config: {
|
154
|
providers?: any[];
|
155
|
useJit?: boolean;
|
156
|
}): void;
|
157
|
configureTestingModule(moduleDef: TestModuleMetadata): void;
|
158
|
compileComponents(): Promise<any>;
|
159
|
private _initIfNeeded();
|
160
|
private _createCompilerAndModule();
|
161
|
private _assertNotInstantiated(methodName, methodDescription);
|
162
|
get(token: any, notFoundValue?: any): any;
|
163
|
execute(tokens: any[], fn: Function, context?: any): any;
|
164
|
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
|
165
|
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
|
166
|
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
|
167
|
overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void;
|
168
|
/**
|
169
|
* Overwrites all providers for the given token with the given provider definition.
|
170
|
*/
|
171
|
overrideProvider(token: any, provider: {
|
172
|
useFactory: Function;
|
173
|
deps: any[];
|
174
|
}): void;
|
175
|
overrideProvider(token: any, provider: {
|
176
|
useValue: any;
|
177
|
}): void;
|
178
|
/**
|
179
|
* Overwrites all providers for the given token with the given provider definition.
|
180
|
*
|
181
|
* @deprecated as it makes all NgModules lazy. Introduced only for migrating off of it.
|
182
|
*/
|
183
|
deprecatedOverrideProvider(token: any, provider: {
|
184
|
useFactory: Function;
|
185
|
deps: any[];
|
186
|
}): void;
|
187
|
deprecatedOverrideProvider(token: any, provider: {
|
188
|
useValue: any;
|
189
|
}): void;
|
190
|
private overrideProviderImpl(token, provider, deprecated?);
|
191
|
createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
192
|
}
|
193
|
/**
|
194
|
* @experimental
|
195
|
*/
|
196
|
export declare function getTestBed(): TestBed;
|
197
|
/**
|
198
|
* Allows injecting dependencies in `beforeEach()` and `it()`.
|
199
|
*
|
200
|
* Example:
|
201
|
*
|
202
|
* ```
|
203
|
* beforeEach(inject([Dependency, AClass], (dep, object) => {
|
204
|
* // some code that uses `dep` and `object`
|
205
|
* // ...
|
206
|
* }));
|
207
|
*
|
208
|
* it('...', inject([AClass], (object) => {
|
209
|
* object.doSomething();
|
210
|
* expect(...);
|
211
|
* })
|
212
|
* ```
|
213
|
*
|
214
|
* Notes:
|
215
|
* - inject is currently a function because of some Traceur limitation the syntax should
|
216
|
* eventually
|
217
|
* becomes `it('...', @Inject (object: AClass, async: AsyncTestCompleter) => { ... });`
|
218
|
*
|
219
|
* @stable
|
220
|
*/
|
221
|
export declare function inject(tokens: any[], fn: Function): () => any;
|
222
|
/**
|
223
|
* @experimental
|
224
|
*/
|
225
|
export declare class InjectSetupWrapper {
|
226
|
private _moduleDef;
|
227
|
constructor(_moduleDef: () => TestModuleMetadata);
|
228
|
private _addModule();
|
229
|
inject(tokens: any[], fn: Function): () => any;
|
230
|
}
|
231
|
/**
|
232
|
* @experimental
|
233
|
*/
|
234
|
export declare function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper;
|
235
|
export declare function withModule(moduleDef: TestModuleMetadata, fn: Function): () => any;
|