Sunday 23 July 2017

Unit testing Express controllers.

Hello all, I've currently got an application which involves two Express servers. One being an api, another being server that queries the api and serves the web pages.I've performed some integration tests with Mocha, Chai and Chai-http on the api, making sure the http response and data returned is correct - but I'm wondering what is the standard way to test controllers that query/render the api. Below is a sample of what a controller would do.exports.get = function (req, res, next) { const posts, foo, bar; /* Query apis, validate and store data in variables */ res.render('partials/index', { posts: posts, foo: foo, bar: bar }); } }); Any help would be greatly appreciated as well as any resources on unit testing in this manor, I've been fiddling about with Sinon and not sure if this is the right direction to go in.Many thanks.

Submitted July 23, 2017 at 05:26PM by wires55

No comments:

Post a Comment