Angular unit testing: If your test isn’t running check your test file name

A quick tip to save you wasting time wondering why Karma isn’t running your test.

Whilst continuing to work through Joe Eames excellent Plurasight course Unit Testing in Angular I came across a problem whereby all tests in one file was not being run by Karma.

I was expecting to see tests under this heading in Karma

HeroesComponent (shallow tests - child component)

But as the output from Karma shows, this test suite is not displayed.

I checked and double checked the test code, watch the clip of the code being written but couldn’t work out why Karma was not running any of the tests in the file. Other tests in different files ran fine.

Took a break and when I came back the problem was staring back at me. The test file name had a typo which meant that it was invisible to Karma.

The incorrect filename was:

heroes.component.shallow.spet.ts

The typo is .spet.ts. Changing this to .spec.ts as shown below

heroes.component.shallow.spec.ts

and now I can see the tests being run.

The Angular documentation states the test file extension must be .spec.ts

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.