Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing (Code Review) #74

Open
jamiecoe opened this issue Oct 14, 2018 · 0 comments
Open

Testing (Code Review) #74

jamiecoe opened this issue Oct 14, 2018 · 0 comments

Comments

@jamiecoe
Copy link

jamiecoe commented Oct 14, 2018

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.

@jamiecoe jamiecoe changed the title Testing Testing (Code Review) Oct 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant