Registry / testing / ng-cache-testing-module

ng-cache-testing-module

JSON →
library1.1.3jsnpmunverified

Angular library (v1.1.3, stable, no recent updates) that caches TestBed configurations between tests to reduce compilation overhead and speed up test suites. Key differentiator: minimal API (single function call) vs alternatives like angular-testing-library or custom caching. Requires @angular/core, rxjs, and zone.js as peer dependencies. Ships TypeScript types.

npm install ng-cache-testing-module
INSTALL
IMPORT
SIG · NG-CACHE-TESTING-M
N
ng-cache-testing-module
testingjavascriptv1.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cacheTestingModule
✓ import { cacheTestingModule } from 'ng-cache-testing-module'
✗ const cacheTestingModule = require('ng-cache-testing-module')
ESM-only; CommonJS require fails. Package exports named module from ESM bundle.
ICacheTestingModuleConfig
✓ import type { ICacheTestingModuleConfig } from 'ng-cache-testing-module'
✗ import { ICacheTestingModuleConfig } from 'ng-cache-testing-module'
Type-only import to avoid runtime error. Config type is exported but not used often.
NG_CACHE_MODULE_CONFIG
✓ import { NG_CACHE_MODULE_CONFIG } from 'ng-cache-testing-module'
✗ import { NG_CACHE_MODULE_CONFIG } from 'ng-cache-testing-module'
Injection token for custom config; not commonly imported directly.

Shows basic usage of cacheTestingModule() in a Jasmine test suite to cache TestBed configuration, improving performance.

import { cacheTestingModule } from 'ng-cache-testing-module'; import { TestBed } from '@angular/core/testing'; import { MyComponent } from './my.component'; describe('MyComponent', () => { cacheTestingModule(); // must be called at suite level, not inside beforeEach beforeEach(() => { TestBed.configureTestingModule({ declarations: [MyComponent] }); }); it('should create', () => { const fixture = TestBed.createComponent(MyComponent); expect(fixture).toBeTruthy(); }); });
Debug
Known issues
gotchacacheTestingModule() must be called inside the root describe block, not inside beforeEach. Calling it inside beforeEach will not cache the module.
fix
Move cacheTestingModule() to the describe callback, outside beforeEach.
affects: >=1.0
gotchaShared state between tests can cause false positives or failures when using cached modules. Services with mutable state persist across tests.
fix
Replace useValue with useFactory in providers to create fresh instances each test.
affects: >=1.0
gotchaGlobal spies created outside of individual tests (e.g., in beforeAll or shared beforeEach) persist across cached module instances, leading to unexpected interactions.
fix
Create spies inside individual it() blocks instead of shared setup.
affects: >=1.0
breakingVersion 1.1.0 changed caching behavior: previously the module configuration was reset automatically; now you must call cacheTestingModule() explicitly in each suite.
fix
Ensure cacheTestingModule() is called in every describe block that should use caching.
affects: >=1.1.0 <1.2.0
deprecatedThe ICacheTestingModuleConfig interface is deprecated in favor of direct injection of NG_CACHE_MODULE_CONFIG for custom caching behavior.
fix
Use the NG_CACHE_MODULE_CONFIG injection token instead of importing ICacheTestingModuleConfig.
affects: >=1.1.0
Errors
Common errors & fixes
Error: Provider parse errors: Cannot instantiate cyclic dependency! NGModule
Using cacheTestingModule() with modules that have circular dependencies causes Angular's provider resolver to fail.
fix
Refactor your Angular module to eliminate circular dependencies or avoid caching in that test suite.
TypeError: Cannot read property 'component' of null
Calling cacheTestingModule() inside a nested describe or beforeEach causes the cached component to be null.
fix
Ensure cacheTestingModule() is called at the top level of the describe block.
ReferenceError: cacheTestingModule is not defined
Trying to use CommonJS require() to import the function, but the package only provides an ESM export.
fix
Use import { cacheTestingModule } from 'ng-cache-testing-module' instead of require().
WARN: 'NG_CACHE_MODULE_CONFIG' has been deprecated and will be removed in a future version.
Directly importing the deprecated ICacheTestingModuleConfig interface triggers a deprecation warning.
fix
Import the type using import type { ICacheTestingModuleConfig } from 'ng-cache-testing-module' with type-only import, or switch to NG_CACHE_MODULE_CONFIG token.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies
@angular/corerequiredCore Angular peer dependency for TestBed and component testing
rxjsrequiredPeer dependency required by Angular's testing utilities
zone.jsrequiredPeer dependency required by Angular's zone system in tests
Agent activity
9 hits · last 30 days
node
8
Resources