-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Jest CLI
The reason you're having to use jest --detectOpenHandles is because the app you provide to supertest is listening on a port, (eg: app.listen()). Therefore, when you run the tests it never closes, which causes jest to complain. If you move this section to a separate file, you can run jest without the --detectOpenHandles flag.
routes.test.js
Currently you’re just testing the status code, rather than the content of the response that comes back. This can be dangerous, for example in your 500 route test. This test is currently passing, but if we run console.log(response.text) - it's not the 500 message you're expecting. It's this:
Error: No default engine was specified and no extension was provided.
What is actually happening is the error thrown and passed to next() is being passed to the 404 route as it also has 4 arguments and comes before the 500 route. However, because you then try to use res.render() instead of res.send(), a 500 response is returned (as you are not using a rendering engine) which unfortunately causes the test to pass.
Testing the response content as well as the status code would catch unlucky coincidences like this.