ng-tester
ng-tester
is an Angular library designed to create structured, opionated spec files for components. It incorporates angular-unit-test-helper to assist with mocking.
Each spec file is created with two subsections:
"DOM Tests"
- Contains Angular TestBed
- Designed for tests that check state changes (i.e.
fixture.detectChanges()
) or require DOM access (i.e. testing UI elements) - Runs slower than functional tests (however as of Angular v9, components are no longer recompiled for each test, significantly improving test run speed from previous Angular versions)
"Functional Tests"
- Designed for functional logic testing
- Runs faster than "DOM Tests", since the DOM is not created for these tests
Usage
- Run
npm install -D ng-tester
- Navigate to project/directory you'd like to generate spec file
- Run
ng generate ng-tester:unit
Output
Below is the test.component.spec.ts
file generated for the command ng g ng-tester:unit --name=test
:
describe'TestComponent',
Peer Dependencies
- @angular/common: >= 9.0.0
- @angular/core: >= 9.0.0
- angular-unit-test-helper: >= 9.3.0
- tslib: >= 1.10.0
Testing Schematic Locally
- In
ng-tester
directory, runnpm run package
- Navigate to project/directory you'd like to generate spec file
- Install
.tgz
file created in step 1 as a devDependency (i.e.npm i ../ng-tester/dist/ng-tester/ng-tester-9.0.0.tgz -D
) - Run
ng generate ng-tester:unit