Tuesday, May 28, 2019

Use Jasmine to make a hollow spy that takes nothing and returns nothing in a Jasmine/Karma test in an Angular 7 application.

In this karma-jasmine test, this...

dispatch: (action: Action) => void = this.emptyPlaceholder;

 
 

...may become:

dispatch: (action: Action) => void = jasmine.createSpy();

 
 

You don't need to import anything at the top of the file to get this to work, not when running the tests. To get the application to compile when running normally you will need to add the following to the "exclude" array inside of tsconfig.app.json:

  • "**/*.spec.ts"
  • "**/testing/*"

No comments:

Post a Comment