When I use Angular CLI to generate a component, the test linked uses the logic foo.spec.ts.

I am reading a tutorial where the test linked uses the logic foo.test.ts.

What's the difference between “foo.spec.ts” and “foo.test.ts"? Is there even one? It is just a matter of taste or is there a logic behind?

  • 1
    I googled test.ts and found a rather telling comment at two such files I found on Github: // This file is required by karma.conf.js and loads recursively all the .spec and framework files – Robert Harvey Jun 29 '18 at 21:07

It is just a "matter of taste" as you describe it. Just a way to group your test files, so that the test runners know what files to load / look in for test methods.

(If you look at the documentation for runner like Jasmine and mocha. You configure "file globs" to tell them how to find the files to run. Some thing like /**/*.test.ts)

In your projects, you could configure anything you want. (Or even just move all your test code to a "test" folder, and not have any special file name conventions)

The *.test.ts and *.spec.ts are just common conventions recommended by the different testing frameworks.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.