-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
func.is-mock-of.ts
57 lines (49 loc) · 1.79 KB
/
func.is-mock-of.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
import { PipeTransform } from '@angular/core';
import { MockedComponent } from '../mock-component/types';
import { MockedDirective } from '../mock-directive/types';
import { MockedModule } from '../mock-module/types';
import { MockedPipe } from '../mock-pipe/types';
import { Type } from './core.types';
import funcIsMock from './func.is-mock';
import { isNgDef } from './func.is-ng-def';
/**
* Checks whether the instance derives from a mock module.
*
* @see https://ng-mocks.sudo.eu/api/helpers/isMockOf
*/
export function isMockOf<T>(instance: any, declaration: Type<T>, ngType: 'm'): instance is MockedModule<T>;
/**
* Checks whether the instance derives from a mock component.
*
* @see https://ng-mocks.sudo.eu/api/helpers/isMockOf
*/
export function isMockOf<T>(instance: any, declaration: Type<T>, ngType: 'c'): instance is MockedComponent<T>;
/**
* Checks whether the instance derives from a mock directive.
*
* @see https://ng-mocks.sudo.eu/api/helpers/isMockOf
*/
export function isMockOf<T>(instance: any, declaration: Type<T>, ngType: 'd'): instance is MockedDirective<T>;
/**
* Checks whether the instance derives from a mock pipe.
*
* @see https://ng-mocks.sudo.eu/api/helpers/isMockOf
*/
export function isMockOf<T extends PipeTransform>(
instance: any,
declaration: Type<T>,
ngType: 'p',
): instance is MockedPipe<T>;
/**
* Checks whether the instance derives from a mock type.
*
* @see https://ng-mocks.sudo.eu/api/helpers/isMockOf
*/
export function isMockOf<T>(instance: any, declaration: Type<T>): instance is T;
export function isMockOf<T>(instance: any, declaration: Type<T>, ngType?: any): instance is T {
return (
funcIsMock(instance) &&
instance.constructor === declaration &&
(ngType ? isNgDef(instance.constructor, ngType) : isNgDef(instance.constructor))
);
}