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:


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


and now I can see the tests being run.

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

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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