/
types.ts
221 lines (197 loc) · 5.94 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import { InjectionToken, PipeTransform, Provider } from '@angular/core';
import { TestBedStatic, TestModuleMetadata } from '@angular/core/testing';
import { AnyType } from '../common/core.types';
/**
* The interface describes the type of the next value in MockBuilder().then().
*/
export interface IMockBuilderResult {
testBed: TestBedStatic;
}
/**
* The interface with flags which are suitable for each declaration in MockBuilder chain functions.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#config
*/
export interface IMockBuilderConfigAll {
/**
* @see https://ng-mocks.sudo.eu/api/MockBuilder#dependency-flag
*/
dependency?: boolean;
/**
* @see https://ng-mocks.sudo.eu/api/MockBuilder#export-flag
*/
export?: boolean;
/**
* @see https://ng-mocks.sudo.eu/api/MockBuilder#shallow-flag
*/
shallow?: boolean;
/**
* @see https://ng-mocks.sudo.eu/api/MockBuilder#onroot-flag
*/
onRoot?: boolean;
}
/**
* The interface with flags which are suitable for modules in MockBuilder chain functions.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#config
*/
export interface IMockBuilderConfigModule {
/**
* @see https://ng-mocks.sudo.eu/api/MockBuilder#exportall-flag
*/
exportAll?: boolean;
}
/**
* The interface with flags which are suitable for components in MockBuilder chain functions.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#config
*/
export interface IMockBuilderConfigComponent {
/**
* @see https://ng-mocks.sudo.eu/api/MockBuilder#render-flag
*/
render?: {
[blockName: string]:
| boolean
| {
$implicit?: any;
variables?: Record<keyof any, any>;
};
};
}
/**
* The interface with flags which are suitable for directives in MockBuilder chain functions.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#config
*/
export interface IMockBuilderConfigDirective {
/**
* @see https://ng-mocks.sudo.eu/api/MockBuilder#render-flag
*/
render?:
| boolean
| {
$implicit?: any;
variables?: Record<keyof any, any>;
};
}
/**
* The interface with flags which are suitable for providers in MockBuilder chain functions.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#config
*/
export interface IMockBuilderConfigMock {
/**
* @see https://ng-mocks.sudo.eu/api/MockBuilder#precise-flag
*/
precise?: boolean;
}
/**
* IMockBuilderConfig is a union of all flags for all MockBuilder chain functions.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#config
*/
export type IMockBuilderConfig =
| IMockBuilderConfigAll
| IMockBuilderConfigModule
| IMockBuilderConfigComponent
| IMockBuilderConfigDirective;
/**
* IMockBuilder describes chain functions of MockBuilder.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder
*/
export interface IMockBuilder extends Promise<IMockBuilderResult> {
/**
* beforeCompileComponents lets extend TestBed.
* For example, to add NO_ERRORS_SCHEMA, please don't do so.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#adding-schemas
*/
beforeCompileComponents(callback: (testBed: TestBedStatic) => void): this;
/**
* .build() returns a declaration which can be used in TestBed.configureTestingModule.
* It is usually helpful with 3rd-party libraries when something should be excluded.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#factory-function
* @see https://ng-mocks.sudo.eu/extra/with-3rd-party
*/
build(): TestModuleMetadata;
/**
* .exclude() excludes declarations.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#exclude
*/
exclude(def: any): this;
/**
* .keep() keeps declarations as they are, and doesn't mock them.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#keep
*/
keep(def: any, config?: IMockBuilderConfigAll & IMockBuilderConfigModule): this;
/**
* .mock() with a transform function is useful to mock pipes.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#mock
*/
mock<T extends PipeTransform>(pipe: AnyType<T>, mock: T['transform'], config?: IMockBuilderConfig): this;
/**
* .mock() for strings is useful to mock string providers.
* However, please considering using tokens instead of string providers.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#mock
*/
mock<T = any>(provider: string, mock: T, config?: IMockBuilderConfig): this;
/**
* .mock() for tokens is useful to provide a mock copy of the token.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#mock
*/
mock<T>(token: InjectionToken<T>, mock: InjectionToken<T> | T | undefined, config?: IMockBuilderConfig): this;
/**
* .mock() for declarations is useful to provide a partial mock implementation.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#mock
*/
mock<T>(
provider: AnyType<T>,
mock: AnyType<T> | Partial<T>,
config?: IMockBuilderConfig & IMockBuilderConfigMock,
): this;
/**
* .mock() for declarations which mocks all methods and properties.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#mock
*/
mock<T>(def: AnyType<T>, config: IMockBuilderConfig): this;
/**
* .mock() for declarations which mocks all methods and properties.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#mock
*/
mock(def: any): this;
/**
* .provide() lets add additional providers to TestBed.
* If you need to mock an existing provider, please use .mock().
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#provide
*/
provide(def: Provider): this;
/**
* .replace() lets substitute declarations.
* For example, BrowserAnimationsModule with NoopAnimationsModule.
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#replace
*/
replace(
source: AnyType<any>,
destination: AnyType<any>,
config?: IMockBuilderConfigAll & IMockBuilderConfigModule,
): this;
}
/**
* IMockBuilderExtended
*
* @see https://ng-mocks.sudo.eu/api/MockBuilder#extending-mockbuilder
*/
export interface IMockBuilderExtended extends IMockBuilder {}