Files
cats.service.spec.ts
What you'll learn
- Stand a dependency in with jest.fn() mocks provided under its token, and script their answers per test
- Test the failure path by making a mock reject, and async code with resolves and rejects
- Assert interactions with toHaveBeenCalledWith and not.toHaveBeenCalled, and know when a spy on the real class is the better 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.
- the owner is looked up by the cat's id, not the owner'scats/cats.service.ts
- the owners system is asked before the cat is checkedcats/cats.service.ts
- an owner lookup failure is swallowed as 'unknown'cats/cats.service.ts
- adopt never checks that the owner existscats/cats.service.ts