Files
cats.e2e-spec.ts
What you'll learn
- Boot the GraphQL application in a test with @nestjs/testing, a fresh one per test so that mutations cannot leak between tests
- Send queries and mutations as POST /graphql with supertest, variables included
- Assert on data, and on errors by their extensions.code, knowing that the HTTP status is 200 either way
- Check a mutation by its effect, querying afterwards, not only by what it answers
Press Run tests to start the app. Its log appears here.Tests
- test/cats.e2e-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.
- cat(id) answers the cat at that index, not the cat with that idcats/cats.service.ts
- a created cat is returned but never storedcats/cats.service.ts
- removeCat answers true and keeps the catcats/cats.service.ts
- a negative age is acceptedcats/create-cat.input.ts