diff --git a/lib/common/core.tokens.ts b/lib/common/core.tokens.ts index 1d9ed2b191..44b79f3c13 100644 --- a/lib/common/core.tokens.ts +++ b/lib/common/core.tokens.ts @@ -11,17 +11,3 @@ export const NG_MOCKS_OVERRIDES = new InjectionToken | AbstractTyp export const NG_MOCKS_GUARDS = new InjectionToken('NG_MOCKS_GUARDS'); export const NG_MOCKS_INTERCEPTORS = new InjectionToken('NG_MOCKS_INTERCEPTORS'); export const NG_MOCKS_ROOT_PROVIDERS = new InjectionToken('NG_MOCKS_ROOT_PROVIDERS'); - -/** - * Use NG_MOCKS_GUARDS instead. - * Will be removed in v11. - * @deprecated - */ -export const NG_GUARDS = NG_MOCKS_GUARDS; - -/** - * Use NG_MOCKS_INTERCEPTORS instead. - * Will be removed in v11. - * @deprecated - */ -export const NG_INTERCEPTORS = NG_MOCKS_INTERCEPTORS; diff --git a/lib/mock-component/mock-component.ts b/lib/mock-component/mock-component.ts index d72411f1c2..8f44d68be0 100644 --- a/lib/mock-component/mock-component.ts +++ b/lib/mock-component/mock-component.ts @@ -16,7 +16,7 @@ import { NG_VALIDATORS, NG_VALUE_ACCESSOR } from '@angular/forms'; import { flatten } from '../common/core.helpers'; import { directiveResolver } from '../common/core.reflect'; -import { AnyType, Type } from '../common/core.types'; +import { Type } from '../common/core.types'; import decorateInputs from '../common/decorate.inputs'; import decorateOutputs from '../common/decorate.outputs'; import decorateQueries from '../common/decorate.queries'; @@ -29,30 +29,13 @@ import mockServiceHelper from '../mock-service/helper'; import { MockedComponent } from './types'; export function MockComponents(...components: Array>): Array>> { - return components.map(component => MockComponent(component, undefined)); + return components.map(MockComponent); } -/** - * @deprecated since version 10.0.0 and will be removed in 11.0.0 - * feel free to open a github issue to discuss an alternative solution. - * /~https://github.com/ike18t/ng-mocks/issues - */ -export function MockComponent( - component: Type, - metaData: core.Directive -): Type>; - /** * @see /~https://github.com/ike18t/ng-mocks#how-to-mock-a-component */ -export function MockComponent( - component: AnyType, - metaData?: core.Directive -): Type>; -export function MockComponent( - component: Type, - metaData?: core.Directive -): Type> { +export function MockComponent(component: Type): Type> { // we are inside of an 'it'. // It's fine to to return a mock copy or to throw an exception if it wasn't replaced with its mock copy in TestBed. if ((getTestBed() as any)._instantiated) { @@ -66,15 +49,12 @@ export function MockComponent( return ngMocksUniverse.cacheDeclarations.get(component); } - let meta: core.Directive | undefined = metaData; - /* istanbul ignore else */ - if (!meta) { - try { - meta = directiveResolver.resolve(component); - } catch (e) { - /* istanbul ignore next */ - throw new Error('ng-mocks is not in JIT mode and cannot resolve declarations'); - } + let meta: core.Directive | undefined; + try { + meta = directiveResolver.resolve(component); + } catch (e) { + /* istanbul ignore next */ + throw new Error('ng-mocks is not in JIT mode and cannot resolve declarations'); } const { exportAs, inputs, outputs, queries, selector, providers } = meta; diff --git a/lib/mock-helper/mock-helper.ts b/lib/mock-helper/mock-helper.ts index 6d35d0069e..916083a5a5 100644 --- a/lib/mock-helper/mock-helper.ts +++ b/lib/mock-helper/mock-helper.ts @@ -3,7 +3,7 @@ import { EventEmitter, InjectionToken, Provider } from '@angular/core'; import { ComponentFixture, TestModuleMetadata } from '@angular/core/testing'; -import { AbstractType, AnyType, Type } from '../common/core.types'; +import { AnyType, Type } from '../common/core.types'; import { NgModuleWithProviders } from '../common/func.is-ng-module-def-with-providers'; import { MockedDebugElement, MockedDebugNode } from '../mock-render/types'; import { MockedFunction } from '../mock-service/types'; @@ -21,75 +21,6 @@ import ngMocksOutput from './mock-helper.output'; import ngMocksReset from './mock-helper.reset'; import ngMocksStub from './mock-helper.stub'; -/* istanbul ignore next */ -/** - * @deprecated use ngMocks instead - */ -export const MockHelper: { - find(debugElement: MockedDebugElement, component: Type): null | MockedDebugElement; - find(debugElement: MockedDebugElement, component: AbstractType): null | MockedDebugElement; - find(debugElement: MockedDebugElement, cssSelector: string): null | MockedDebugElement; - findAll(debugElement: MockedDebugElement, component: Type): Array>; - findAll(debugElement: MockedDebugElement, component: AbstractType): Array>; - findAll(debugElement: MockedDebugElement, cssSelector: string): Array>; - findDirective(debugNode: MockedDebugNode, directive: Type): undefined | T; - findDirective(debugNode: MockedDebugNode, directive: AbstractType): undefined | T; - findDirectiveOrFail(debugNode: MockedDebugNode, directive: Type): T; - findDirectiveOrFail(debugNode: MockedDebugNode, directive: AbstractType): T; - findDirectives(debugNode: MockedDebugNode, directive: Type): T[]; - findDirectives(debugNode: MockedDebugNode, directive: AbstractType): T[]; - findOrFail(debugElement: MockedDebugElement, component: Type): MockedDebugElement; - findOrFail(debugElement: MockedDebugElement, component: AbstractType): MockedDebugElement; - findOrFail(debugElement: MockedDebugElement, cssSelector: string): MockedDebugElement; - getDirective(debugNode: MockedDebugNode, directive: Type): undefined | T; - getDirective(debugNode: MockedDebugNode, directive: AbstractType): undefined | T; - getDirectiveOrFail(debugNode: MockedDebugNode, directive: Type): T; - getDirectiveOrFail(debugNode: MockedDebugNode, directive: AbstractType): T; - getInput(debugNode: MockedDebugNode, input: string): undefined | T; - getInputOrFail(debugNode: MockedDebugNode, input: string): T; - getOutput(debugNode: MockedDebugNode, output: string): undefined | EventEmitter; - getOutputOrFail(debugNode: MockedDebugNode, output: string): EventEmitter; - mockService(instance: I, overrides: O): I & O; - mockService(instance: any, name: string, style?: 'get' | 'set'): T; -} = { - getInput: (debugNode: MockedDebugNode, input: string): any => ngMocks.input(debugNode, input, undefined), - - getInputOrFail: (debugNode: MockedDebugNode, input: string): any => ngMocks.input(debugNode, input), - - getOutput: (debugNode: MockedDebugNode, output: string): any => ngMocks.output(debugNode, output, undefined), - - getOutputOrFail: (debugNode: MockedDebugNode, output: string): any => ngMocks.output(debugNode, output), - - getDirectiveOrFail: (debugNode: MockedDebugNode, directive: Type): T => ngMocks.get(debugNode, directive), - - getDirective: (debugNode: MockedDebugNode, directive: Type): undefined | T => - ngMocks.get(debugNode, directive, undefined), - - findDirectiveOrFail: (debugNode: MockedDebugNode, directive: Type): T => - ngMocks.findInstance(debugNode, directive), - - findDirective: (debugNode: MockedDebugNode, directive: Type): undefined | T => - ngMocks.findInstance(debugNode, directive, undefined), - - findDirectives: (debugNode: MockedDebugNode, directive: Type): T[] => - ngMocks.findInstances(debugNode, directive), - - findOrFail: (el: MockedDebugElement, sel: any) => ngMocks.find(el, sel), - - // tslint:disable-next-line:no-null-keyword - find: (el: MockedDebugElement, sel: any) => ngMocks.find(el, sel, null), - - findAll: (el: MockedDebugElement, sel: any) => ngMocks.findAll(el, sel), - - mockService: (instance: any, override: any, style?: 'get' | 'set'): T => { - if (typeof override !== 'object') { - return ngMocks.stub(instance, override, style); - } - - return ngMocks.stub(instance, override); - }, -}; - /** * @see /~https://github.com/ike18t/ng-mocks#ngmocks */