Tuesday 10 January 2017

Unit Testing a Controller with http responses

HiIm fairly new to unit testing. I was wondering what would be the best way to unit test a function in my controller that deals with http responses. An example of a function is below:/**Gets all users *@param {Object} req request@param {Object} res response@param {Function} next function to call in middleware*/var getAll = function(req, res, next) {userService.getAllUsers().then(function(result) { res.status(200).json(result); }).catch(next); };I'm currently using libraries such as chai and mocha to test out my services but that was fairly straight forward as I was dealing with input coming in and output being returned. I'm not quite sure what to do in this case where nothing is really being returned but a http response is being made.I've searched for some help but what comes up when looking for unit testing with http responses seems to be more along the lines of integration tests rather than unit testing .Any suggestions for methods or libraries to unit test this kind of function would be greatly appreciated. :)edit: This is the first time im posting here so im not entire sure how to put the code above in a block.

Submitted January 10, 2017 at 02:00PM by DotaSlimz

No comments:

Post a Comment