From 6fbf18d746c8cea5d284dfd9abbf5fbb51ac17eb Mon Sep 17 00:00:00 2001 From: satanTime Date: Sat, 14 May 2022 12:20:32 +0200 Subject: [PATCH] fix(core): correct type for AbstractType --- libs/ng-mocks/src/lib/common/core.helpers.ts | 7 ++- libs/ng-mocks/src/lib/common/core.types.ts | 16 ++++-- .../src/lib/common/ng-mocks-universe.ts | 6 +-- .../src/lib/mock-builder/mock-builder.ts | 6 +-- .../func.get-from-node-injector.ts | 6 +-- .../lib/mock-helper/func.get-from-node-ivy.ts | 4 +- .../mock-helper/func.get-from-node-scan.ts | 4 +- .../func.get-from-node-standard.ts | 4 +- .../src/lib/mock-helper/func.get-from-node.ts | 6 +-- .../mock-helper/mock-helper.default-config.ts | 6 +-- .../mock-helper/mock-helper.default-mock.ts | 6 +-- .../mock-helper/mock-helper.global-exclude.ts | 6 +-- .../mock-helper/mock-helper.global-keep.ts | 6 +-- .../mock-helper/mock-helper.global-mock.ts | 6 +-- .../mock-helper/mock-helper.global-wipe.ts | 6 +-- .../src/lib/mock-helper/mock-helper.ts | 49 +++++++------------ .../src/lib/mock-instance/mock-instance.ts | 16 +++--- .../src/lib/mock-provider/mock-provider.ts | 12 ++--- .../lib/mock-render/mock-render-factory.ts | 4 +- .../src/lib/mock-render/mock-render.ts | 4 +- 20 files changed, 81 insertions(+), 99 deletions(-) diff --git a/libs/ng-mocks/src/lib/common/core.helpers.ts b/libs/ng-mocks/src/lib/common/core.helpers.ts index 5aeb823664..43e52105cf 100644 --- a/libs/ng-mocks/src/lib/common/core.helpers.ts +++ b/libs/ng-mocks/src/lib/common/core.helpers.ts @@ -1,9 +1,8 @@ -import { InjectionToken } from '@angular/core'; import { getTestBed } from '@angular/core/testing'; import coreDefineProperty from './core.define-property'; import coreReflectParametersResolve from './core.reflect.parameters-resolve'; -import { AnyType, Type } from './core.types'; +import { AnyDeclaration, AnyType, Type } from './core.types'; import funcGetGlobal from './func.get-global'; import funcGetName from './func.get-name'; @@ -13,7 +12,7 @@ import funcGetName from './func.get-name'; * @deprecated * @internal */ -export const getTestBedInjection = (token: AnyType | InjectionToken): I | undefined => { +export const getTestBedInjection = (token: AnyDeclaration): I | undefined => { try { // istanbul ignore next return getInjection(token); @@ -28,7 +27,7 @@ export const getTestBedInjection = (token: AnyType | InjectionToken): I * @deprecated * @internal */ -export const getInjection = (token: AnyType | InjectionToken): I => { +export const getInjection = (token: AnyDeclaration): I => { const testBed: any = getTestBed(); // istanbul ignore next diff --git a/libs/ng-mocks/src/lib/common/core.types.ts b/libs/ng-mocks/src/lib/common/core.types.ts index fb69c82fe3..57b0edbf01 100644 --- a/libs/ng-mocks/src/lib/common/core.types.ts +++ b/libs/ng-mocks/src/lib/common/core.types.ts @@ -1,17 +1,18 @@ // istanbul ignore file +/* eslint-disable @typescript-eslint/ban-types */ -import { DebugNode } from '@angular/core'; +import { DebugNode, InjectionToken } from '@angular/core'; import { ComponentFixture } from '@angular/core/testing'; /** - * It has to be an interface. + * A5 requires it to be a type, because interface doesn't work with A5. * It matches abstract classes. * * @internal */ -export interface AbstractType extends Function { +type AbstractType = Function & { prototype: T; -} +}; /** * It has to be an interface. @@ -30,6 +31,13 @@ export interface Type extends Function { */ export type AnyType = Type | AbstractType; +/** + * It matches any declaration in angular. + * + * @internal + */ +export type AnyDeclaration = AnyType | InjectionToken; + /** * DebugNodeSelector describes supported types of selectors * to search elements and instances in fixtures. diff --git a/libs/ng-mocks/src/lib/common/ng-mocks-universe.ts b/libs/ng-mocks/src/lib/common/ng-mocks-universe.ts index 007a60d243..597d67faf0 100644 --- a/libs/ng-mocks/src/lib/common/ng-mocks-universe.ts +++ b/libs/ng-mocks/src/lib/common/ng-mocks-universe.ts @@ -1,9 +1,7 @@ -import { InjectionToken } from '@angular/core'; - import { IMockBuilderConfig } from '../mock-builder/types'; import coreConfig from './core.config'; -import { AnyType } from './core.types'; +import { AnyDeclaration } from './core.types'; import funcGetGlobal from './func.get-global'; import funcGetName from './func.get-name'; @@ -33,7 +31,7 @@ interface NgMocksUniverse { hasBuildDeclaration: (def: any) => boolean; isExcludedDef: (def: any) => boolean; isProvidedDef: (def: any) => boolean; - touches: Set | InjectionToken | string>; + touches: Set | string>; } funcGetGlobal().ngMocksUniverse = funcGetGlobal().ngMocksUniverse || {}; diff --git a/libs/ng-mocks/src/lib/mock-builder/mock-builder.ts b/libs/ng-mocks/src/lib/mock-builder/mock-builder.ts index 0e6ca6a59d..7c6a76ed2c 100644 --- a/libs/ng-mocks/src/lib/mock-builder/mock-builder.ts +++ b/libs/ng-mocks/src/lib/mock-builder/mock-builder.ts @@ -1,13 +1,11 @@ -import { InjectionToken } from '@angular/core'; - import { flatten } from '../common/core.helpers'; -import { AnyType } from '../common/core.types'; +import { AnyDeclaration } from '../common/core.types'; import { NgModuleWithProviders } from '../common/func.is-ng-module-def-with-providers'; import { MockBuilderPerformance } from './mock-builder.performance'; import { IMockBuilder } from './types'; -export type MockBuilderParam = string | AnyType | InjectionToken | NgModuleWithProviders; +export type MockBuilderParam = string | AnyDeclaration | NgModuleWithProviders; /** * MockBuilder provides reach and simple interfaces of chain functions diff --git a/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-injector.ts b/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-injector.ts index 8bfcfe8e29..11c6949bbd 100644 --- a/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-injector.ts +++ b/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-injector.ts @@ -1,7 +1,7 @@ -import { DebugNode, InjectionToken, Injector } from '@angular/core'; +import { DebugNode, Injector } from '@angular/core'; import coreInjector from '../common/core.injector'; -import { Type } from '../common/core.types'; +import { AnyDeclaration } from '../common/core.types'; import { isNgDef } from '../common/func.is-ng-def'; import { Node } from './func.get-from-node'; @@ -19,7 +19,7 @@ const getParentWithInjector = (node: (DebugNode & Node) | null): Injector | unde return undefined; }; -export default (result: T[], node: DebugNode & Node, proto: Type | InjectionToken): void => { +export default (result: T[], node: DebugNode & Node, proto: AnyDeclaration): void => { if (!node.injector || node.injector.constructor.name === 'NullInjector') { return; } diff --git a/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-ivy.ts b/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-ivy.ts index 7fe85369c9..7e840b94a3 100644 --- a/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-ivy.ts +++ b/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-ivy.ts @@ -1,6 +1,6 @@ import { DebugNode } from '@angular/core'; -import { Type } from '../common/core.types'; +import { AnyType } from '../common/core.types'; import { Node } from './func.get-from-node'; import funcGetFromNodeElement from './func.get-from-node-element'; @@ -44,7 +44,7 @@ const detectContext = (node: DebugNode): any => { const contextToNodes = (context: any): any => (Array.isArray(context) ? context : context?.lView); -export default (result: T[], node: (DebugNode & Node) | null | undefined, proto: Type): void => { +export default (result: T[], node: (DebugNode & Node) | null | undefined, proto: AnyType): void => { if (!node || node._debugContext) { return; } diff --git a/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-scan.ts b/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-scan.ts index 757ed1f317..7f549cac92 100644 --- a/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-scan.ts +++ b/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-scan.ts @@ -1,6 +1,6 @@ import { DebugNode } from '@angular/core'; -import { Type } from '../common/core.types'; +import { AnyType } from '../common/core.types'; const detectGatherFlag = (gather: boolean, el: DebugNode | null, node: any): boolean => { // LContainer for structural directives can be a trigger for pipes. @@ -52,7 +52,7 @@ const scan = ( el: DebugNode | null; nodes: any[]; normalize: (item: any) => any; - proto: Type; + proto: AnyType; result: T[]; }, gatherDefault: boolean, diff --git a/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-standard.ts b/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-standard.ts index 0078a91be5..a444c9da01 100644 --- a/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-standard.ts +++ b/libs/ng-mocks/src/lib/mock-helper/func.get-from-node-standard.ts @@ -1,6 +1,6 @@ import { DebugNode } from '@angular/core'; -import { Type } from '../common/core.types'; +import { AnyType } from '../common/core.types'; import { Node } from './func.get-from-node'; import funcGetFromNodeElement from './func.get-from-node-element'; @@ -20,7 +20,7 @@ const normalize = (item: any): any => { return null; }; -export default (result: T[], node: (DebugNode & Node) | null | undefined, proto: Type): void => { +export default (result: T[], node: (DebugNode & Node) | null | undefined, proto: AnyType): void => { if (!node || !node._debugContext) { return; } diff --git a/libs/ng-mocks/src/lib/mock-helper/func.get-from-node.ts b/libs/ng-mocks/src/lib/mock-helper/func.get-from-node.ts index 728e3cc7f5..295e0c907d 100644 --- a/libs/ng-mocks/src/lib/mock-helper/func.get-from-node.ts +++ b/libs/ng-mocks/src/lib/mock-helper/func.get-from-node.ts @@ -1,6 +1,6 @@ -import { DebugNode, InjectionToken } from '@angular/core'; +import { DebugNode } from '@angular/core'; -import { Type } from '../common/core.types'; +import { AnyDeclaration } from '../common/core.types'; import { isNgDef } from '../common/func.is-ng-def'; import funcGetFromNodeInjector from './func.get-from-node-injector'; @@ -28,7 +28,7 @@ export interface Node { parent?: (DebugNode & Node) | null; } -export default (result: T[], node: DebugNode & Node, proto: Type | InjectionToken): T[] => { +export default (result: T[], node: DebugNode & Node, proto: AnyDeclaration): T[] => { funcGetFromNodeInjector(result, node, proto); if (!isNgDef(proto, 't')) { funcGetFromNodeStandard(result, node, proto); diff --git a/libs/ng-mocks/src/lib/mock-helper/mock-helper.default-config.ts b/libs/ng-mocks/src/lib/mock-helper/mock-helper.default-config.ts index 45198a64fd..34f1c511c5 100644 --- a/libs/ng-mocks/src/lib/mock-helper/mock-helper.default-config.ts +++ b/libs/ng-mocks/src/lib/mock-helper/mock-helper.default-config.ts @@ -1,12 +1,10 @@ -import { InjectionToken } from '@angular/core'; - import { flatten } from '../common/core.helpers'; -import { AnyType } from '../common/core.types'; +import { AnyDeclaration } from '../common/core.types'; import ngMocksUniverse from '../common/ng-mocks-universe'; import { IMockBuilderConfig } from '../mock-builder/types'; export default ( - def: AnyType | InjectionToken | string | Array | InjectionToken | string>, + def: AnyDeclaration | string | Array | string>, config?: IMockBuilderConfig, ): void => { const map = ngMocksUniverse.getConfigMock(); diff --git a/libs/ng-mocks/src/lib/mock-helper/mock-helper.default-mock.ts b/libs/ng-mocks/src/lib/mock-helper/mock-helper.default-mock.ts index be1b554db7..bc7ee0f69e 100644 --- a/libs/ng-mocks/src/lib/mock-helper/mock-helper.default-mock.ts +++ b/libs/ng-mocks/src/lib/mock-helper/mock-helper.default-mock.ts @@ -1,11 +1,11 @@ -import { InjectionToken, Injector } from '@angular/core'; +import { Injector } from '@angular/core'; import { flatten } from '../common/core.helpers'; -import { AnyType } from '../common/core.types'; +import { AnyDeclaration } from '../common/core.types'; import ngMocksUniverse from '../common/ng-mocks-universe'; export default ( - def: AnyType | InjectionToken | string | Array | InjectionToken | string>, + def: AnyDeclaration | string | Array | string>, callback?: (instance: undefined | T, injector: Injector) => void | Partial, ): void => { const map = ngMocksUniverse.getOverrides(); diff --git a/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-exclude.ts b/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-exclude.ts index 8f75b2206f..c0c1800287 100644 --- a/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-exclude.ts +++ b/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-exclude.ts @@ -1,11 +1,9 @@ -import { InjectionToken } from '@angular/core'; - -import { AnyType } from '../common/core.types'; +import { AnyDeclaration } from '../common/core.types'; import ngMocksUniverse from '../common/ng-mocks-universe'; import funcGlobalPrepare from './func.global-prepare'; -export default (source: AnyType | InjectionToken): void => { +export default (source: AnyDeclaration): void => { funcGlobalPrepare(); ngMocksUniverse.getDefaults().set(source, ['exclude']); }; diff --git a/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-keep.ts b/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-keep.ts index 43e555f1fa..f116795c35 100644 --- a/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-keep.ts +++ b/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-keep.ts @@ -1,11 +1,9 @@ -import { InjectionToken } from '@angular/core'; - -import { AnyType } from '../common/core.types'; +import { AnyDeclaration } from '../common/core.types'; import ngMocksUniverse from '../common/ng-mocks-universe'; import funcGlobalPrepare from './func.global-prepare'; -export default (source: AnyType | InjectionToken): void => { +export default (source: AnyDeclaration): void => { funcGlobalPrepare(); ngMocksUniverse.getDefaults().set(source, ['keep']); }; diff --git a/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-mock.ts b/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-mock.ts index 36c0980305..8aca0c5bb9 100644 --- a/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-mock.ts +++ b/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-mock.ts @@ -1,11 +1,9 @@ -import { InjectionToken } from '@angular/core'; - -import { AnyType } from '../common/core.types'; +import { AnyDeclaration } from '../common/core.types'; import ngMocksUniverse from '../common/ng-mocks-universe'; import funcGlobalPrepare from './func.global-prepare'; -export default (source: AnyType | InjectionToken): void => { +export default (source: AnyDeclaration): void => { funcGlobalPrepare(); ngMocksUniverse.getDefaults().set(source, ['mock']); }; diff --git a/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-wipe.ts b/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-wipe.ts index 5a6abc1f96..32da9eef4a 100644 --- a/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-wipe.ts +++ b/libs/ng-mocks/src/lib/mock-helper/mock-helper.global-wipe.ts @@ -1,12 +1,10 @@ -import { InjectionToken } from '@angular/core'; - -import { AnyType } from '../common/core.types'; +import { AnyDeclaration } from '../common/core.types'; import ngMocksUniverse from '../common/ng-mocks-universe'; import funcGlobalPrepare from './func.global-prepare'; import mockHelperDefaultMock from './mock-helper.default-mock'; -export default (source: AnyType | InjectionToken): void => { +export default (source: AnyDeclaration): void => { funcGlobalPrepare(); ngMocksUniverse.getDefaults().delete(source); mockHelperDefaultMock(source); diff --git a/libs/ng-mocks/src/lib/mock-helper/mock-helper.ts b/libs/ng-mocks/src/lib/mock-helper/mock-helper.ts index 1df8f45c88..7b2dd38eec 100644 --- a/libs/ng-mocks/src/lib/mock-helper/mock-helper.ts +++ b/libs/ng-mocks/src/lib/mock-helper/mock-helper.ts @@ -3,7 +3,7 @@ import { DebugNode, EventEmitter, InjectionToken, Injector, Provider, TemplateRef } from '@angular/core'; import { ComponentFixture, TestModuleMetadata } from '@angular/core/testing'; -import { AnyType, DebugNodeSelector, Type } from '../common/core.types'; +import { AnyDeclaration, AnyType, DebugNodeSelector, Type } from '../common/core.types'; import { NgModuleWithProviders } from '../common/func.is-ng-module-def-with-providers'; import { IMockBuilderConfig } from '../mock-builder/types'; import { MockedDebugElement, MockedDebugNode } from '../mock-render/types'; @@ -37,7 +37,7 @@ export const ngMocks: { * * @see https://ng-mocks.sudo.eu/api/ngMocks/defaultConfig */ - defaultConfig(token: string | InjectionToken | AnyType, config?: IMockBuilderConfig): void; + defaultConfig(token: string | AnyDeclaration, config?: IMockBuilderConfig): void; /** * ngMocks.defaultMock sets default customizations of mock tokens. @@ -82,7 +82,7 @@ export const ngMocks: { * @see https://ng-mocks.sudo.eu/api/ngMocks/defaultMock */ defaultMock( - defs: Array | InjectionToken>, + defs: Array>, handler?: (value: undefined | T, injector: Injector) => undefined | Partial, config?: IMockBuilderConfig, ): void; @@ -97,7 +97,7 @@ export const ngMocks: { * ngMocks.globalExclude(TranslationModule); * ``` */ - globalExclude(source: AnyType | InjectionToken): void; + globalExclude(source: AnyDeclaration): void; /** * ngMocks.globalKeep configures which declarations, providers and tokens @@ -109,7 +109,7 @@ export const ngMocks: { * ngMocks.globalKeep(TranslationModule); * ``` */ - globalKeep(source: AnyType | InjectionToken): void; + globalKeep(source: AnyDeclaration): void; /** * ngMocks.globalMock configures which declarations, providers and tokens @@ -121,7 +121,7 @@ export const ngMocks: { * ngMocks.globalMock(TranslationModule); * ``` */ - globalMock(source: AnyType | InjectionToken): void; + globalMock(source: AnyDeclaration): void; /** * ngMocks.globalReplace configures which declarations, providers and tokens @@ -145,7 +145,7 @@ export const ngMocks: { * ngMocks.globalWipe(BrowserAnimationsModule); * ``` */ - globalWipe(source: AnyType | InjectionToken): void; + globalWipe(source: AnyDeclaration): void; /** * ngMocks.change triggers ControlValueAccessor update. @@ -650,7 +650,7 @@ export const ngMocks: { * const myDirective = ngMocks.get('my-component', MyDirective); * ``` */ - get(elSelector: DebugNodeSelector, provider: AnyType | InjectionToken): T; + get(elSelector: DebugNodeSelector, provider: AnyDeclaration): T; /** * ngMocks.get tries to get an instance of declaration, provider or token @@ -663,7 +663,7 @@ export const ngMocks: { * const myDirective = ngMocks.get('my-component', MyDirective, null); * ``` */ - get(elSelector: DebugNodeSelector, provider: AnyType | InjectionToken, notFoundValue: D): D | T; + get(elSelector: DebugNodeSelector, provider: AnyDeclaration, notFoundValue: D): D | T; /** * ngMocks.findInstance searches for an instance of declaration, provider or token, @@ -677,7 +677,7 @@ export const ngMocks: { * const config = ngMocks.findInstance(APP_CONFIG); * ``` */ - findInstance(instanceClass: AnyType | InjectionToken): T; + findInstance(instanceClass: AnyDeclaration): T; /** * ngMocks.findInstance searches for an instance of declaration, provider or token @@ -691,7 +691,7 @@ export const ngMocks: { * const config = ngMocks.findInstance(debugElement, APP_CONFIG); * ``` */ - findInstance(elSelector: DebugNodeSelector, instanceClass: AnyType | InjectionToken): T; + findInstance(elSelector: DebugNodeSelector, instanceClass: AnyDeclaration): T; /** * ngMocks.findInstance searches for an instance of declaration, provider or token, @@ -704,7 +704,7 @@ export const ngMocks: { * const service = ngMocks.findInstance(AuthService, null); * const config = ngMocks.findInstance(APP_CONFIG, false); */ - findInstance(instanceClass: AnyType | InjectionToken, notFoundValue: D): D | T; + findInstance(instanceClass: AnyDeclaration, notFoundValue: D): D | T; /** * ngMocks.findInstance searches for an instance of declaration, provider or token @@ -718,11 +718,7 @@ export const ngMocks: { * const config = ngMocks.findInstance(debugElement, APP_CONFIG, false); * ``` */ - findInstance( - elSelector: DebugNodeSelector, - instanceClass: AnyType | InjectionToken, - notFoundValue: D, - ): D | T; + findInstance(elSelector: DebugNodeSelector, instanceClass: AnyDeclaration, notFoundValue: D): D | T; /** * ngMocks.findInstances searches for all instances of declaration, provider or token, @@ -736,7 +732,7 @@ export const ngMocks: { * const configs = ngMocks.findInstances(APP_CONFIG); * ``` */ - findInstances(instanceClass: AnyType | InjectionToken): T[]; + findInstances(instanceClass: AnyDeclaration): T[]; /** * ngMocks.findInstances searches for all instances of declaration, provider or token @@ -750,7 +746,7 @@ export const ngMocks: { * const configs = ngMocks.findInstances(debugElement, APP_CONFIG); * ``` */ - findInstances(elSelector: DebugNodeSelector, instanceClass: AnyType | InjectionToken): T[]; + findInstances(elSelector: DebugNodeSelector, instanceClass: AnyDeclaration): T[]; /** * ngMocks.findTemplateRef searches for a TemplateRef which is matching the selector, @@ -938,22 +934,15 @@ export const ngMocks: { * @see https://ng-mocks.sudo.eu/api/ngMocks/guts */ guts( - keep: - | AnyType - | InjectionToken - | Provider - | Array | InjectionToken | Provider> - | null - | undefined, + keep: AnyDeclaration | Provider | Array | Provider> | null | undefined, mock?: - | AnyType - | InjectionToken + | AnyDeclaration | NgModuleWithProviders | Provider - | Array | InjectionToken | NgModuleWithProviders | Provider> + | Array | NgModuleWithProviders | Provider> | null | undefined, - exclude?: AnyType | InjectionToken | Array | InjectionToken> | null | undefined, + exclude?: AnyDeclaration | Array> | null | undefined, ): TestModuleMetadata; /** diff --git a/libs/ng-mocks/src/lib/mock-instance/mock-instance.ts b/libs/ng-mocks/src/lib/mock-instance/mock-instance.ts index 0313292c67..c52808fec1 100644 --- a/libs/ng-mocks/src/lib/mock-instance/mock-instance.ts +++ b/libs/ng-mocks/src/lib/mock-instance/mock-instance.ts @@ -1,6 +1,6 @@ import { InjectionToken, Injector } from '@angular/core'; -import { AbstractType, Type } from '../common/core.types'; +import { AnyDeclaration, AnyType } from '../common/core.types'; import funcImportExists from '../common/func.import-exists'; import ngMocksStack, { NgMocksStack } from '../common/ng-mocks-stack'; import ngMocksUniverse from '../common/ng-mocks-universe'; @@ -59,7 +59,7 @@ if (typeof beforeEach !== 'undefined') { } const mockInstanceConfig = ( - declaration: Type | AbstractType | InjectionToken, + declaration: AnyDeclaration, name: string | undefined, stub: any, encapsulation?: 'get' | 'set', @@ -93,7 +93,7 @@ const mockInstanceConfig = ( * ``` */ export function MockInstance T[K]>( - instance: Type | AbstractType, + instance: AnyType, name: K, stub: S, encapsulation: 'get', @@ -113,7 +113,7 @@ export function MockInstance void>( - instance: Type | AbstractType, + instance: AnyType, name: K, stub: S, encapsulation: 'set', @@ -132,7 +132,7 @@ export function MockInstance( - instance: Type | AbstractType, + instance: AnyType, name: K, stub: S, ): S; @@ -189,7 +189,7 @@ export function MockInstance( * ``` */ export function MockInstance( - declaration: Type | AbstractType, + declaration: AnyType, init?: (instance: T, injector: Injector | undefined) => void | Partial, ): void; @@ -217,13 +217,13 @@ export function MockInstance( * ``` */ export function MockInstance( - declaration: Type | AbstractType, + declaration: AnyType, config?: { init?: (instance: T, injector: Injector | undefined) => void | Partial; }, ): void; -export function MockInstance(declaration: Type | AbstractType | InjectionToken, ...args: any[]) { +export function MockInstance(declaration: AnyDeclaration, ...args: any[]) { funcImportExists(declaration, 'MockInstance'); if (args.length > 0) { diff --git a/libs/ng-mocks/src/lib/mock-provider/mock-provider.ts b/libs/ng-mocks/src/lib/mock-provider/mock-provider.ts index ea2a1dc451..0f905c5fb3 100644 --- a/libs/ng-mocks/src/lib/mock-provider/mock-provider.ts +++ b/libs/ng-mocks/src/lib/mock-provider/mock-provider.ts @@ -8,7 +8,7 @@ import { ValueProvider, } from '@angular/core'; -import { AnyType } from '../common/core.types'; +import { AnyDeclaration, AnyType } from '../common/core.types'; import funcImportExists from '../common/func.import-exists'; import mockHelperStub from '../mock-helper/mock-helper.stub'; import helperUseFactory from '../mock-service/helper.use-factory'; @@ -30,7 +30,7 @@ const defaultValue = {}; * }); * ``` */ -export function MockProviders(...providers: Array | InjectionToken>): FactoryProvider[] { +export function MockProviders(...providers: Array>): FactoryProvider[] { return providers.map((provider: any) => MockProvider(provider, defaultValue)); } @@ -105,7 +105,7 @@ export function MockProvider(provider: string, useValue?: Partial): * ``` */ export function MockProvider( - provider: AnyType | InjectionToken, + provider: AnyDeclaration, value: ValueProvider['useValue'], style: 'useValue', multi?: ValueProvider['multi'], @@ -126,7 +126,7 @@ export function MockProvider( * ``` */ export function MockProvider( - provider: AnyType | InjectionToken, + provider: AnyDeclaration, value: ExistingProvider['useExisting'], style: 'useExisting', multi?: ExistingProvider['multi'], @@ -150,7 +150,7 @@ export function MockProvider( * ``` */ export function MockProvider( - provider: AnyType | InjectionToken, + provider: AnyDeclaration, value: StaticClassProvider['useClass'], style: 'useClass', multiDeps?: @@ -184,7 +184,7 @@ export function MockProvider( * ``` */ export function MockProvider( - provider: AnyType | InjectionToken, + provider: AnyDeclaration, value: FactoryProvider['useFactory'], style: 'useFactory', multiDeps?: diff --git a/libs/ng-mocks/src/lib/mock-render/mock-render-factory.ts b/libs/ng-mocks/src/lib/mock-render/mock-render-factory.ts index 8d31c688a8..1e8d8e4e2b 100644 --- a/libs/ng-mocks/src/lib/mock-render/mock-render-factory.ts +++ b/libs/ng-mocks/src/lib/mock-render/mock-render-factory.ts @@ -2,7 +2,7 @@ import { DebugElement, Directive, InjectionToken } from '@angular/core'; import { getTestBed, TestBed } from '@angular/core/testing'; import coreDefineProperty from '../common/core.define-property'; -import { AnyType, Type } from '../common/core.types'; +import { AnyDeclaration, AnyType, Type } from '../common/core.types'; import funcImportExists from '../common/func.import-exists'; import { isNgDef } from '../common/func.is-ng-def'; import ngMocksStack from '../common/ng-mocks-stack'; @@ -246,7 +246,7 @@ export function MockRenderFactory; export function MockRenderFactory( - template: string | AnyType | InjectionToken, + template: string | AnyDeclaration, bindings?: undefined | null | TKeys[], options: IMockRenderFactoryOptions = {}, ): any { diff --git a/libs/ng-mocks/src/lib/mock-render/mock-render.ts b/libs/ng-mocks/src/lib/mock-render/mock-render.ts index a3303361e8..1cc735651b 100644 --- a/libs/ng-mocks/src/lib/mock-render/mock-render.ts +++ b/libs/ng-mocks/src/lib/mock-render/mock-render.ts @@ -1,6 +1,6 @@ import { InjectionToken } from '@angular/core'; -import { AnyType } from '../common/core.types'; +import { AnyDeclaration, AnyType } from '../common/core.types'; import { MockRenderFactory } from './mock-render-factory'; import { IMockRenderOptions, MockedComponentFixture } from './types'; @@ -104,7 +104,7 @@ export function MockRender ): MockedComponentFixture; export function MockRender>( - template?: string | AnyType | InjectionToken, + template?: string | AnyDeclaration, params?: TComponent, flags: boolean | IMockRenderOptions = true, ): any {