diff --git a/lib/common/mock.ts b/lib/common/mock.ts index ab83343f13..e5858bb318 100644 --- a/lib/common/mock.ts +++ b/lib/common/mock.ts @@ -154,8 +154,8 @@ const applyOverrides = (instance: any, mockOf: any, injector?: Injector): void = if (instance.__ngMocksConfig.init) { callbacks.push(instance.__ngMocksConfig.init); } - if (ngMocksUniverse.config.get(mockOf)?.init) { - callbacks.push(ngMocksUniverse.config.get(mockOf).init); + if (ngMocksUniverse.configInstance.get(mockOf)?.init) { + callbacks.push(ngMocksUniverse.configInstance.get(mockOf).init); } for (const callback of callbacks) { diff --git a/lib/common/ng-mocks-universe.ts b/lib/common/ng-mocks-universe.ts index 66dc99267f..57209d9845 100644 --- a/lib/common/ng-mocks-universe.ts +++ b/lib/common/ng-mocks-universe.ts @@ -12,6 +12,7 @@ interface NgMocksUniverse { cacheDeclarations: Map; cacheProviders: Map; config: Map; + configInstance: Map; flags: Set; getLocalMocks: () => Array<[any, any]>; getOverrides: () => Map; @@ -29,6 +30,7 @@ ngMocksUniverse.builtProviders = new Map(); ngMocksUniverse.cacheDeclarations = new Map(); ngMocksUniverse.cacheProviders = new Map(); ngMocksUniverse.config = new Map(); +ngMocksUniverse.configInstance = new Map(); ngMocksUniverse.flags = new Set(coreConfig.flags); ngMocksUniverse.global = new Map(); ngMocksUniverse.touches = new Set(); diff --git a/lib/mock-builder/mock-builder-stash.ts b/lib/mock-builder/mock-builder-stash.ts index f29635f84b..cc0e6b103d 100644 --- a/lib/mock-builder/mock-builder-stash.ts +++ b/lib/mock-builder/mock-builder-stash.ts @@ -11,6 +11,7 @@ export class MockBuilderStash { cacheDeclarations: ngMocksUniverse.cacheDeclarations, cacheProviders: ngMocksUniverse.cacheProviders, config: ngMocksUniverse.config, + configInstance: ngMocksUniverse.configInstance, flags: ngMocksUniverse.flags, touches: ngMocksUniverse.touches, }; @@ -20,6 +21,7 @@ export class MockBuilderStash { ngMocksUniverse.cacheDeclarations = new Map(); ngMocksUniverse.cacheProviders = new Map(); ngMocksUniverse.config = new Map(); + ngMocksUniverse.configInstance = new Map(); ngMocksUniverse.flags = new Set(coreConfig.flags); ngMocksUniverse.touches = new Set(); } diff --git a/lib/mock-helper/mock-helper.reset.ts b/lib/mock-helper/mock-helper.reset.ts index 75518f8249..161cfeb07d 100644 --- a/lib/mock-helper/mock-helper.reset.ts +++ b/lib/mock-helper/mock-helper.reset.ts @@ -6,6 +6,7 @@ export default (): void => { ngMocksUniverse.cacheDeclarations = new Map(); ngMocksUniverse.cacheProviders = new Map(); ngMocksUniverse.config = new Map(); + ngMocksUniverse.configInstance = new Map(); ngMocksUniverse.flags = new Set(coreConfig.flags); ngMocksUniverse.touches = new Set(); }; diff --git a/lib/mock-instance/mock-instance.ts b/lib/mock-instance/mock-instance.ts index a713d56b68..d4e56f9611 100644 --- a/lib/mock-instance/mock-instance.ts +++ b/lib/mock-instance/mock-instance.ts @@ -18,8 +18,10 @@ const reporter: jasmine.CustomReporter = { const set = ngMocksUniverse.getLocalMocks(); while (set.length) { const [declaration, config] = set.pop() || /* istanbul ignore next */ []; - const universeConfig = ngMocksUniverse.config.has(declaration) ? ngMocksUniverse.config.get(declaration) : {}; - ngMocksUniverse.config.set(declaration, { + const universeConfig = ngMocksUniverse.configInstance.has(declaration) + ? ngMocksUniverse.configInstance.get(declaration) + : {}; + ngMocksUniverse.configInstance.set(declaration, { ...universeConfig, ...config, }); @@ -71,16 +73,18 @@ export function MockInstance( export function MockInstance(declaration: Type | AbstractType | InjectionToken, data?: any) { const config = typeof data === 'function' ? { init: data } : data; - const universeConfig = ngMocksUniverse.config.has(declaration) ? ngMocksUniverse.config.get(declaration) : {}; + const universeConfig = ngMocksUniverse.configInstance.has(declaration) + ? ngMocksUniverse.configInstance.get(declaration) + : {}; restore(declaration, universeConfig); if (config) { - ngMocksUniverse.config.set(declaration, { + ngMocksUniverse.configInstance.set(declaration, { ...universeConfig, ...config, }); } else { - ngMocksUniverse.config.set(declaration, { + ngMocksUniverse.configInstance.set(declaration, { ...universeConfig, init: undefined, }); @@ -88,5 +92,5 @@ export function MockInstance(declaration: Type | AbstractType | Injecti } export function MockReset() { - ngMocksUniverse.config.clear(); + ngMocksUniverse.configInstance.clear(); } diff --git a/lib/mock-service/helper.use-factory.ts b/lib/mock-service/helper.use-factory.ts index 2e3d275aae..a829533f44 100644 --- a/lib/mock-service/helper.use-factory.ts +++ b/lib/mock-service/helper.use-factory.ts @@ -49,8 +49,8 @@ export default ( if (overrides) { callbacks.push(overrides); } - if (ngMocksUniverse.config.get(def)?.init) { - callbacks.push(ngMocksUniverse.config.get(def).init); + if (ngMocksUniverse.configInstance.get(def)?.init) { + callbacks.push(ngMocksUniverse.configInstance.get(def).init); } return applyCallback(def, instance, callbacks, injector, overrides);