Angular Unit Test Generator

Boilerplate code for Angular unit tests


Writing unit tests for Angular components, services, directives or pipes requires a lot of boilerplate code to be in your spec.ts files before you can even start writing a unit test. This webapp generates most boilerplate code for you, based on the component code that you paste.

It generates the necessary import statements for the dependencies injected in the constructor and provides you the code for the providers section of the Angular TestBed testing module. You can copy/paste this code into the spec files that the Angular CLI has created for you when you created the component, service, directive or pipe.

The generated providers section uses Jasmine's createSpyObj to mock the injected dependencies and the methods it can find in your component. This way, the unit tests are not depending on the dependencies. It supports custom private names for the injected dependencies, for example if you add: private service: HeroService in the constructor, it will generate a mock based on the methods that you call on the this.service object.

To do