JavaScript JavaScript Unit Testing Improving Our Tests Making Tests Easier with Fixtures: Setup

Michael Rockett
Michael Rockett
40,321 Points

How do you go about testing express routes?

I understand how you would test an API where json is returned with the res object, but I don't understand how you could test anything when you need to render a template like res.render.

I've looked at loads of tutorials online but all the examples involve returning json, which you can't do if your returning a template

Any help with this would be greatly appreciated Thanks, Mike

1 Answer

Tom Geraghty
Tom Geraghty
24,159 Points

From the docs, response.render()

Renders a view and sends the rendered HTML string to the client.

What does the rest of your test suite look like? You should be able to take the HTML string that is returned by res.render and inspect it for something that makes your tests pass.