When trying to test my method, the following error appears:
TypeError: cannot call 'json' method from undefined
Below is my code, I would get the same error for "status" if I remove res.status from the test method.
How to define 'json', so I am not getting an exception:
res.status (404) .json (error);
when testing this feature.
stores.js
{ //the get function declared above (removed to ease of reading) // using a queryBuilder var query = Stores.find(); query.sort('storeName'); query.exec(function (err, results) { if (err) res.send(err); if (_.isEmpty(results)) { var error = { message: "No Results", errorKey: "XXX" } res.status(404).json(error); return; } return res.json(results); }); }
storesTest.js
it('should on get call of stores, return a error', function () { var mockFind = { sort: function(sortOrder) { return this; }, exec: function (callback) { callback('Error'); } }; Stores.get.should.be.a["function"];
source share