Skip to content

Commit

Permalink
fix: avoiding cache in providers' declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
satanTime committed Jan 10, 2021
1 parent cb71bdb commit da98414
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/mock-service/helper.resolve-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const anyDiffers = (a: any, b: any, ...keys: string[]): boolean => {
return false;
};

const createFromResolution = (provide: any, resolution: any, multi?: boolean) => {
const createFromResolution = (provide: any, resolution: any) => {
let mockDef = resolution;

const existingMock = ngMocksUniverse.builtProviders.get(provide);
Expand All @@ -33,7 +33,7 @@ const createFromResolution = (provide: any, resolution: any, multi?: boolean) =>
};
}

return multi && typeof mockDef === 'object' ? { ...mockDef, multi } : mockDef;
return mockDef;
};

const isSuitableProvider = (provider: any, provide: any): boolean =>
Expand Down Expand Up @@ -115,7 +115,7 @@ const createPredefinedMockProvider = (provider: any, provide: any): any => {
return undefined;
};

const createMockProvider = (provider: any, provide: any, resolutions: Map<any, any>, change: () => void) => {
const createMockProvider = (provider: any, provide: any, change: () => void) => {
let mockDef = createPredefinedMockProvider(provider, provide);

if (!mockDef && ngMocksUniverse.flags.has('skipMock')) {
Expand All @@ -127,9 +127,6 @@ const createMockProvider = (provider: any, provide: any, resolutions: Map<any, a
}

mockDef = replaceWithMocks(provider, provide, mockDef);
if (!isNgInjectionToken(provide) || provider !== mockDef) {
resolutions.set(provide, mockDef);
}
if (!areEqualDefs(mockDef, provider, provide)) {
change();
}
Expand Down Expand Up @@ -180,10 +177,10 @@ export default (provider: any, resolutions: Map<any, any>, changed?: () => void)
return change();
}
if (resolutions.has(provide)) {
return createFromResolution(provide, resolutions.get(provide), multi);
return createFromResolution(provide, resolutions.get(provide));
}

const mockDef = createMockProvider(provider, provide, resolutions, change);
const mockDef = createMockProvider(provider, provide, change);

return multi && typeof mockDef === 'object' ? { ...mockDef, multi } : mockDef;
};

0 comments on commit da98414

Please sign in to comment.