README
Angular Unit Test Helper
Helper functions to help write unit tests in Angular using mocks and spies
Goal
Minimal feature set to bridge obvious gaps in jasmine's support of modern JavaScript features. Ideally, I'd like to be using an auto-mocking library, but they don't play well with Angular's TestBed
and RxJS\BehaviorSubject
.
Here's a great article about auto-mocking libraries: https://hackernoon.com/with-typescript-3-and-substitute-js-you-are-already-missing-out-when-mocking-or-faking-a3b3240c4607.
Install
Add the package to your Angular project with npm:
npm i -D angular-unit-test-helper
Example Projects
Check out my sample projects that leverage angular-unit-test-helper
:
Use the ng-tester
package to generate robust and efficient unit tests using angular-unit-test-helper
.
Usage
npm i -D ng-tester
npx ng g ng-tester:unit
For more information see https://github.com/bjsawyer/ng-tester/.
Features
autoSpyObj(classUnderTest: Function, spyProperties: string[] = [], observableStrategy = ObservablePropertyStrategy.Observable)
An extension of jasmine.createSpyObj
with automatic discovery of functions and property getters given a Class, without requiring an instance of an object.
If you'd want to spy on a property without a getter, then you can simply pass in the property name like autoSpyObj(WeatherService, ['currentWeather