Testing an API End to End

Testing an API End to End: Testing an API with Supertest, Testing Errors, with a Fresh Start for Every Test.

Updated

  1. Testing an API with Supertest (Journeyman): Supertest hands a request straight to an Express app, with no server running and no port, so a test can check the status code, the headers and the JSON body that come back, for a GET and for a POST with a body.
  2. Testing Errors, with a Fresh Start for Every Test (Journeyman): An API's error answers, such as 400, 404 and 409 with their JSON bodies, are part of what it promises, so they get tests too, and beforeEach puts the in-memory data back before every test, so each one starts from the same seats.