ng-mocks 13.4.2 → 13.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ng-mocks.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- import { ChangeDetectorRef, DebugElement, DebugNode, ElementRef, EventEmitter, FactoryProvider, InjectionToken, Injector, PipeTransform, Provider, TemplateRef, ViewContainerRef } from '@angular/core';
1
+ import { ChangeDetectorRef, ClassProvider, DebugElement, DebugNode, ElementRef, EventEmitter, ExistingProvider, FactoryProvider, InjectionToken, Injector, PipeTransform, Provider, StaticClassProvider, TemplateRef, ValueProvider, ViewContainerRef } from '@angular/core';
2
2
  import { ComponentFixture, MetadataOverride, TestBed, TestModuleMetadata } from '@angular/core/testing';
3
3
 
4
- interface AbstractType<T> extends Function {
4
+ declare type AbstractType<T> = Function & {
5
5
  prototype: T;
6
- }
6
+ };
7
7
  interface Type<T> extends Function {
8
8
  new (...args: any[]): T;
9
9
  }
10
10
  declare type AnyType<T> = Type<T> | AbstractType<T>;
11
+ declare type AnyDeclaration<T> = AnyType<T> | InjectionToken<T>;
11
12
  declare type DebugNodeSelector = DebugNode | ComponentFixture<any> | string | [
12
13
  string
13
14
  ] | [
@@ -77,14 +78,14 @@ export declare const NG_MOCKS_ROOT_PROVIDERS: InjectionToken<void>;
77
78
  * @deprecated
78
79
  * @internal
79
80
  */
80
- export declare const getTestBedInjection: <I>(token: AnyType<I> | InjectionToken<I>) => I | undefined;
81
+ export declare const getTestBedInjection: <I>(token: AnyDeclaration<I>) => I | undefined;
81
82
  /**
82
83
  * It will be removed from public interface with the next release: A14
83
84
  *
84
85
  * @deprecated
85
86
  * @internal
86
87
  */
87
- export declare const getInjection: <I>(token: Type<I> | InjectionToken<I>) => I;
88
+ export declare const getInjection: <I>(token: AnyDeclaration<I>) => I;
88
89
  /**
89
90
  * The interface describes the type of the next value in MockBuilder().then().
90
91
  */
@@ -897,7 +898,7 @@ export declare const isNgInjectionToken: (token: any) => token is InjectionToken
897
898
  * MockInstance(ArbitraryService, 'enabled', () => false, 'get');
898
899
  * ```
899
900
  */
900
- export declare function MockInstance<T extends object, K extends keyof T, S extends () => T[K]>(instance: Type<T> | AbstractType<T>, name: K, stub: S, encapsulation: "get"): S;
901
+ export declare function MockInstance<T extends object, K extends keyof T, S extends () => T[K]>(instance: AnyType<T>, name: K, stub: S, encapsulation: "get"): S;
901
902
  /**
902
903
  * This signature of MockInstance lets customize the setters of a property.
903
904
  *
@@ -911,7 +912,7 @@ export declare function MockInstance<T extends object, K extends keyof T, S exte
911
912
  * MockInstance(ArbitraryService, 'enabled', value => relServiceEnabled = value, 'set');
912
913
  * ```
913
914
  */
914
- export declare function MockInstance<T extends object, K extends keyof T, S extends (value: T[K]) => void>(instance: Type<T> | AbstractType<T>, name: K, stub: S, encapsulation: "set"): S;
915
+ export declare function MockInstance<T extends object, K extends keyof T, S extends (value: T[K]) => void>(instance: AnyType<T>, name: K, stub: S, encapsulation: "set"): S;
915
916
  /**
916
917
  * This signature of MockInstance lets customize the properties and methods.
917
918
  *
@@ -924,7 +925,7 @@ export declare function MockInstance<T extends object, K extends keyof T, S exte
924
925
  * MockInstance(ArbitraryModule, 'currentUser', mockUser);
925
926
  * ```
926
927
  */
927
- export declare function MockInstance<T extends object, K extends keyof T, S extends T[K]>(instance: Type<T> | AbstractType<T>, name: K, stub: S): S;
928
+ export declare function MockInstance<T extends object, K extends keyof T, S extends T[K]>(instance: AnyType<T>, name: K, stub: S): S;
928
929
  /**
929
930
  * This signature of MockInstance lets customize tokens with a callback.
930
931
  *
@@ -968,7 +969,7 @@ export declare function MockInstance<T>(declaration: InjectionToken<T>, config?:
968
969
  * });
969
970
  * ```
970
971
  */
971
- export declare function MockInstance<T>(declaration: Type<T> | AbstractType<T>, init?: (instance: T, injector: Injector | undefined) => void | Partial<T>): void;
972
+ export declare function MockInstance<T>(declaration: AnyType<T>, init?: (instance: T, injector: Injector | undefined) => void | Partial<T>): void;
972
973
  /**
973
974
  * This signature of MockInstance lets customize the instances of mock classes with a callback.
974
975
  * You can return a shape or change the instance.
@@ -992,7 +993,7 @@ export declare function MockInstance<T>(declaration: Type<T> | AbstractType<T>,
992
993
  * });
993
994
  * ```
994
995
  */
995
- export declare function MockInstance<T>(declaration: Type<T> | AbstractType<T>, config?: {
996
+ export declare function MockInstance<T>(declaration: AnyType<T>, config?: {
996
997
  init?: (instance: T, injector: Injector | undefined) => void | Partial<T>;
997
998
  }): void;
998
999
  /**
@@ -1035,7 +1036,7 @@ interface NgModuleWithProviders<T = any> {
1035
1036
  ngModule: Type<T>;
1036
1037
  providers?: Provider[];
1037
1038
  }
1038
- declare type MockBuilderParam = string | AnyType<any> | InjectionToken<any> | NgModuleWithProviders;
1039
+ declare type MockBuilderParam = string | AnyDeclaration<any> | NgModuleWithProviders;
1039
1040
  /**
1040
1041
  * MockBuilder provides reach and simple interfaces of chain functions
1041
1042
  * to build desired mock environment for tests.
@@ -1213,7 +1214,7 @@ export declare function MockDeclaration<T>(declaration: Type<T>): Type<MockedPip
1213
1214
  * });
1214
1215
  * ```
1215
1216
  */
1216
- export declare function MockProviders(...providers: Array<AnyType<any> | InjectionToken<any>>): FactoryProvider[];
1217
+ export declare function MockProviders(...providers: Array<AnyDeclaration<any>>): FactoryProvider[];
1217
1218
  /**
1218
1219
  * MockProvider creates a mock provider out of passed an arbitrary service.
1219
1220
  *
@@ -1267,6 +1268,82 @@ export declare function MockProvider<I>(provider: InjectionToken<I>, useValue?:
1267
1268
  * ```
1268
1269
  */
1269
1270
  export declare function MockProvider<I = any>(provider: string, useValue?: Partial<I>): FactoryProvider;
1271
+ /**
1272
+ * MockProvider generates useValue based on passed parameters.
1273
+ *
1274
+ * @see https://ng-mocks.sudo.eu/api/MockProvider#useValue
1275
+ *
1276
+ * ```ts
1277
+ * TestBed.configureTestingModule({
1278
+ * providers: [
1279
+ * MockProvider(AuthService, {isLoggedIn: true}, 'useValue'),
1280
+ * MockProvider(APP_ROUTES, 5, 'useValue', true), // multi flag
1281
+ * ],
1282
+ * });
1283
+ * ```
1284
+ */
1285
+ export declare function MockProvider<I>(provider: AnyDeclaration<I>, value: ValueProvider["useValue"], style: "useValue", multi?: ValueProvider["multi"]): ValueProvider;
1286
+ /**
1287
+ * MockProvider generates useExisting based on passed parameters.
1288
+ *
1289
+ * @see https://ng-mocks.sudo.eu/api/MockProvider#useExisting
1290
+ *
1291
+ * ```ts
1292
+ * TestBed.configureTestingModule({
1293
+ * providers: [
1294
+ * MockProvider(AuthService, MockAuthService, 'useExisting', true),
1295
+ * MockProvider(APP_ROUTES, MOCK_ROUTES, 'useExisting', true), // multi flag
1296
+ * ],
1297
+ * });
1298
+ * ```
1299
+ */
1300
+ export declare function MockProvider<I>(provider: AnyDeclaration<I>, value: ExistingProvider["useExisting"], style: "useExisting", multi?: ExistingProvider["multi"]): ExistingProvider;
1301
+ /**
1302
+ * MockProvider generates useClass based on passed parameters.
1303
+ *
1304
+ * @see https://ng-mocks.sudo.eu/api/MockProvider#useClass
1305
+ *
1306
+ * ```ts
1307
+ * TestBed.configureTestingModule({
1308
+ * providers: [
1309
+ * MockProvider(AuthService, MockAuthService, 'useClass', [ctorDep1, ctorDep2]),
1310
+ * MockProvider(UserService, MockUserService, 'useClass', {
1311
+ * multi: true, // multi flag
1312
+ * deps: [ctorDep1, ctorDep2],
1313
+ * }),
1314
+ * ],
1315
+ * });
1316
+ * ```
1317
+ */
1318
+ export declare function MockProvider<I>(provider: AnyDeclaration<I>, value: StaticClassProvider["useClass"], style: "useClass", multiDeps?: StaticClassProvider["multi"] | StaticClassProvider["deps"] | {
1319
+ multi?: StaticClassProvider["multi"];
1320
+ deps?: StaticClassProvider["deps"];
1321
+ }): ClassProvider;
1322
+ /**
1323
+ * MockProvider generates useFactory based on passed parameters.
1324
+ *
1325
+ * @see https://ng-mocks.sudo.eu/api/MockProvider#useFactory
1326
+ *
1327
+ * ```ts
1328
+ * TestBed.configureTestingModule({
1329
+ * providers: [
1330
+ * MockProvider(AuthService, (dep1, dep2) => {
1331
+ * // ...
1332
+ * }, 'useFactory', [ctorDep1, ctorDep2]),
1333
+ * MockProvider(UserService, (dep1, dep2) => {
1334
+ * // ...
1335
+ * }, 'useFactory', {
1336
+ * multi: true, // multi flag
1337
+ * deps: [ctorDep1, ctorDep2],
1338
+ * }),
1339
+ * ],
1340
+ * });
1341
+ * ```
1342
+ */
1343
+ export declare function MockProvider<I>(provider: AnyDeclaration<I>, value: FactoryProvider["useFactory"], style: "useFactory", multiDeps?: FactoryProvider["multi"] | FactoryProvider["deps"] | {
1344
+ multi?: FactoryProvider["multi"];
1345
+ deps?: FactoryProvider["deps"];
1346
+ }): FactoryProvider;
1270
1347
  /**
1271
1348
  * MockService creates a mock instance out of an object or a class.
1272
1349
  * Primitives are converted to undefined.
@@ -1426,7 +1503,7 @@ export declare const ngMocks: {
1426
1503
  *
1427
1504
  * @see https://ng-mocks.sudo.eu/api/ngMocks/defaultConfig
1428
1505
  */
1429
- defaultConfig<T>(token: string | InjectionToken<T> | AnyType<T>, config?: IMockBuilderConfig): void;
1506
+ defaultConfig<T>(token: string | AnyDeclaration<T>, config?: IMockBuilderConfig): void;
1430
1507
  /**
1431
1508
  * ngMocks.defaultMock sets default customizations of mock tokens.
1432
1509
  * It helps to avoid repetitions from test to test.
@@ -1454,7 +1531,7 @@ export declare const ngMocks: {
1454
1531
  *
1455
1532
  * @see https://ng-mocks.sudo.eu/api/ngMocks/defaultMock
1456
1533
  */
1457
- defaultMock<T = any>(defs: Array<AnyType<T> | InjectionToken<T>>, handler?: (value: undefined | T, injector: Injector) => undefined | Partial<T>, config?: IMockBuilderConfig): void;
1534
+ defaultMock<T = any>(defs: Array<AnyDeclaration<T>>, handler?: (value: undefined | T, injector: Injector) => undefined | Partial<T>, config?: IMockBuilderConfig): void;
1458
1535
  /**
1459
1536
  * ngMocks.globalExclude configures which declarations, providers and tokens
1460
1537
  * should be excluded from mocks.
@@ -1465,7 +1542,7 @@ export declare const ngMocks: {
1465
1542
  * ngMocks.globalExclude(TranslationModule);
1466
1543
  * ```
1467
1544
  */
1468
- globalExclude(source: AnyType<any> | InjectionToken<any>): void;
1545
+ globalExclude(source: AnyDeclaration<any>): void;
1469
1546
  /**
1470
1547
  * ngMocks.globalKeep configures which declarations, providers and tokens
1471
1548
  * should not be mocked and will stay as they are in mocks.
@@ -1476,7 +1553,7 @@ export declare const ngMocks: {
1476
1553
  * ngMocks.globalKeep(TranslationModule);
1477
1554
  * ```
1478
1555
  */
1479
- globalKeep(source: AnyType<any> | InjectionToken<any>): void;
1556
+ globalKeep(source: AnyDeclaration<any>): void;
1480
1557
  /**
1481
1558
  * ngMocks.globalMock configures which declarations, providers and tokens
1482
1559
  * should be mocked in kept declarations.
@@ -1487,7 +1564,7 @@ export declare const ngMocks: {
1487
1564
  * ngMocks.globalMock(TranslationModule);
1488
1565
  * ```
1489
1566
  */
1490
- globalMock(source: AnyType<any> | InjectionToken<any>): void;
1567
+ globalMock(source: AnyDeclaration<any>): void;
1491
1568
  /**
1492
1569
  * ngMocks.globalReplace configures which declarations, providers and tokens
1493
1570
  * should be substituted in mocks.
@@ -1509,7 +1586,7 @@ export declare const ngMocks: {
1509
1586
  * ngMocks.globalWipe(BrowserAnimationsModule);
1510
1587
  * ```
1511
1588
  */
1512
- globalWipe(source: AnyType<any> | InjectionToken<any>): void;
1589
+ globalWipe(source: AnyDeclaration<any>): void;
1513
1590
  /**
1514
1591
  * ngMocks.change triggers ControlValueAccessor update.
1515
1592
  *
@@ -1982,7 +2059,7 @@ export declare const ngMocks: {
1982
2059
  * const myDirective = ngMocks.get('my-component', MyDirective);
1983
2060
  * ```
1984
2061
  */
1985
- get<T>(elSelector: DebugNodeSelector, provider: AnyType<T> | InjectionToken<T>): T;
2062
+ get<T>(elSelector: DebugNodeSelector, provider: AnyDeclaration<T>): T;
1986
2063
  /**
1987
2064
  * ngMocks.get tries to get an instance of declaration, provider or token
1988
2065
  * from the element which is matching a selector, otherwise the notFoundValue.
@@ -1994,7 +2071,7 @@ export declare const ngMocks: {
1994
2071
  * const myDirective = ngMocks.get('my-component', MyDirective, null);
1995
2072
  * ```
1996
2073
  */
1997
- get<T, D>(elSelector: DebugNodeSelector, provider: AnyType<T> | InjectionToken<T>, notFoundValue: D): D | T;
2074
+ get<T, D>(elSelector: DebugNodeSelector, provider: AnyDeclaration<T>, notFoundValue: D): D | T;
1998
2075
  /**
1999
2076
  * ngMocks.findInstance searches for an instance of declaration, provider or token,
2000
2077
  * and returns the first one.
@@ -2007,7 +2084,7 @@ export declare const ngMocks: {
2007
2084
  * const config = ngMocks.findInstance(APP_CONFIG);
2008
2085
  * ```
2009
2086
  */
2010
- findInstance<T>(instanceClass: AnyType<T> | InjectionToken<T>): T;
2087
+ findInstance<T>(instanceClass: AnyDeclaration<T>): T;
2011
2088
  /**
2012
2089
  * ngMocks.findInstance searches for an instance of declaration, provider or token
2013
2090
  * starting from an element, and returns the first one.
@@ -2020,7 +2097,7 @@ export declare const ngMocks: {
2020
2097
  * const config = ngMocks.findInstance(debugElement, APP_CONFIG);
2021
2098
  * ```
2022
2099
  */
2023
- findInstance<T>(elSelector: DebugNodeSelector, instanceClass: AnyType<T> | InjectionToken<T>): T;
2100
+ findInstance<T>(elSelector: DebugNodeSelector, instanceClass: AnyDeclaration<T>): T;
2024
2101
  /**
2025
2102
  * ngMocks.findInstance searches for an instance of declaration, provider or token,
2026
2103
  * and returns the first one, otherwise the notFoundValue.
@@ -2032,7 +2109,7 @@ export declare const ngMocks: {
2032
2109
  * const service = ngMocks.findInstance(AuthService, null);
2033
2110
  * const config = ngMocks.findInstance(APP_CONFIG, false);
2034
2111
  */
2035
- findInstance<T, D>(instanceClass: AnyType<T> | InjectionToken<T>, notFoundValue: D): D | T;
2112
+ findInstance<T, D>(instanceClass: AnyDeclaration<T>, notFoundValue: D): D | T;
2036
2113
  /**
2037
2114
  * ngMocks.findInstance searches for an instance of declaration, provider or token
2038
2115
  * starting from an element, and returns the first one, otherwise the notFoundValue.
@@ -2045,7 +2122,7 @@ export declare const ngMocks: {
2045
2122
  * const config = ngMocks.findInstance(debugElement, APP_CONFIG, false);
2046
2123
  * ```
2047
2124
  */
2048
- findInstance<T, D>(elSelector: DebugNodeSelector, instanceClass: AnyType<T> | InjectionToken<T>, notFoundValue: D): D | T;
2125
+ findInstance<T, D>(elSelector: DebugNodeSelector, instanceClass: AnyDeclaration<T>, notFoundValue: D): D | T;
2049
2126
  /**
2050
2127
  * ngMocks.findInstances searches for all instances of declaration, provider or token,
2051
2128
  * and returns an array of them.
@@ -2058,7 +2135,7 @@ export declare const ngMocks: {
2058
2135
  * const configs = ngMocks.findInstances(APP_CONFIG);
2059
2136
  * ```
2060
2137
  */
2061
- findInstances<T>(instanceClass: AnyType<T> | InjectionToken<T>): T[];
2138
+ findInstances<T>(instanceClass: AnyDeclaration<T>): T[];
2062
2139
  /**
2063
2140
  * ngMocks.findInstances searches for all instances of declaration, provider or token
2064
2141
  * starting from an element, and returns an array of them.
@@ -2071,7 +2148,7 @@ export declare const ngMocks: {
2071
2148
  * const configs = ngMocks.findInstances(debugElement, APP_CONFIG);
2072
2149
  * ```
2073
2150
  */
2074
- findInstances<T>(elSelector: DebugNodeSelector, instanceClass: AnyType<T> | InjectionToken<T>): T[];
2151
+ findInstances<T>(elSelector: DebugNodeSelector, instanceClass: AnyDeclaration<T>): T[];
2075
2152
  /**
2076
2153
  * ngMocks.findTemplateRef searches for a TemplateRef which is matching the selector,
2077
2154
  * and returns the first found, otherwise the notFoundValue.
@@ -2245,7 +2322,7 @@ export declare const ngMocks: {
2245
2322
  *
2246
2323
  * @see https://ng-mocks.sudo.eu/api/ngMocks/guts
2247
2324
  */
2248
- guts(keep: AnyType<any> | InjectionToken<any> | Provider | Array<AnyType<any> | InjectionToken<any> | Provider> | null | undefined, mock?: AnyType<any> | InjectionToken<any> | NgModuleWithProviders | Provider | Array<AnyType<any> | InjectionToken<any> | NgModuleWithProviders | Provider> | null | undefined, exclude?: AnyType<any> | InjectionToken<any> | Array<AnyType<any> | InjectionToken<any>> | null | undefined): TestModuleMetadata;
2325
+ guts(keep: AnyDeclaration<any> | Provider | Array<AnyDeclaration<any> | Provider> | null | undefined, mock?: AnyDeclaration<any> | NgModuleWithProviders | Provider | Array<AnyDeclaration<any> | NgModuleWithProviders | Provider> | null | undefined, exclude?: AnyDeclaration<any> | Array<AnyDeclaration<any>> | null | undefined): TestModuleMetadata;
2249
2326
  /**
2250
2327
  * ngMocks.faster lets reuse the same TestBed between tests instead of resetting it.
2251
2328
  *
@@ -2331,6 +2408,12 @@ export declare const ngMocks: {
2331
2408
  onTestBedFlushNeed?: "throw" | "warn" | "i-know-but-disable" | null;
2332
2409
  }): void;
2333
2410
  };
2411
+ /**
2412
+ * This signature of MockRender lets create an empty fixture.
2413
+ *
2414
+ * @see https://ng-mocks.sudo.eu/api/MockRender
2415
+ */
2416
+ export declare function MockRender(): MockedComponentFixture<void, void>;
2334
2417
  /**
2335
2418
  * This signature of MockRender lets create a fixture to access a token.
2336
2419
  *
@@ -2361,14 +2444,6 @@ export declare function MockRender<MComponent, TComponent extends object = Recor
2361
2444
  * @see https://ng-mocks.sudo.eu/api/MockRender
2362
2445
  */
2363
2446
  export declare function MockRender<MComponent>(template: AnyType<MComponent>): MockedComponentFixture<MComponent, MComponent>;
2364
- /**
2365
- * This signature of MockRender with an empty template does not have the point.
2366
- *
2367
- * @see https://ng-mocks.sudo.eu/api/MockRender
2368
- */
2369
- export declare function MockRender(template: ""): ComponentFixture<void> & {
2370
- point: undefined;
2371
- };
2372
2447
  /**
2373
2448
  * This signature of MockRender without params should not autocomplete any keys of any types.
2374
2449
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-mocks",
3
- "version": "13.4.2",
3
+ "version": "13.5.2",
4
4
  "description": "An Angular testing library for creating mock services, components, directives, pipes and modules in unit tests, which includes shallow rendering, precise stubs to dump child dependencies, supports Angular 5 6 7 8 9 10 11 12 13, jasmine and jest.",
5
5
  "keywords": [
6
6
  "angular",