16

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
  • 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 Commented Jun 29, 2018 at 21:07

1 Answer 1

22

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.

1
  • 1
    I have seen some people use them for unit and integration testing. Where "spec" is for unit testing and "test" for integration testing. Commented Nov 6, 2023 at 14:45

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