Skip to content

Commit

Permalink
fix: removal dependency on reflect-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
satanTime committed Dec 27, 2020
1 parent 091125f commit 57cedfb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 17 additions & 4 deletions lib/common/core.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ export const extractDependency = (deps: any[], set?: Set<any>): void => {
}
};

// First we try to eval es2015 style and if it fails to use es5 transpilation in the catch block.
// The next step is to respect constructor parameters as the parent class via jitReflector.
export const extendClass = <I extends object>(base: Type<I>): Type<I> => {
const extendClassicClass = <I extends object>(base: Type<I>): Type<I> => {
let child: any;

(window as any).ngMocksParent = base;
Expand All @@ -100,7 +98,22 @@ export const extendClass = <I extends object>(base: Type<I>): Type<I> => {
child = ClassEs5;
}
(window as any).ngMocksParent = undefined;
child.parameters = jitReflector.parameters(base);

return child;
};

// First we try to eval es2015 style and if it fails to use es5 transpilation in the catch block.
// The next step is to respect constructor parameters as the parent class via jitReflector.
export const extendClass = <I extends object>(base: Type<I>): Type<I> => {
const child: typeof base &
Partial<{
parameters: any[][];
}> = extendClassicClass(base);

const parameters = jitReflector.parameters(base);
if (parameters.length) {
child.parameters = parameters;
}

return child;
};
4 changes: 3 additions & 1 deletion lib/common/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export interface MockConfig {
export class Mock {
protected __ngMocksConfig!: ngMocksMockConfig;

public constructor(@Optional() injector?: Injector) {
public constructor(injector?: Injector) {
const mockOf = (this.constructor as any).mockOf;

// istanbul ignore else
Expand All @@ -175,3 +175,5 @@ export class Mock {
applyOverrides(this, mockOf, injector);
}
}

(Mock as any).parameters = [[Injector, new Optional()]];

0 comments on commit 57cedfb

Please sign in to comment.