Files
cats.service.spec.ts
What you'll learn
- Provide a mock repository under getRepositoryToken(Entity) in a testing module, so the service under test never touches a database
- Script findOneBy, save, create and delete per test with mockResolvedValue and friends, and assert what the service asked for
- Decide what a repository test proves (the service's rules) and what it cannot (the query), and when an integration test on sqljs is the right tool
Press Run tests to start the app. Its log appears here.Tests
- cats/cats.service.spec.tsrun to see its tests
Bugs your tests must catch
Each of these replaces one file with a buggy version and runs your tests again. A bug is caught when at least one test fails against it. Tests that pass whatever the code does are not tests.
- create builds the entity but never saves itcats/cats.service.ts
- findOne returns null for a missing cat instead of a 404cats/cats.service.ts
- adopt lets an adopted cat be adopted againcats/cats.service.ts
- adopt changes the cat in memory and never savescats/cats.service.ts
- remove ignores how many rows were deletedcats/cats.service.ts