I am trying to test my routes that have mongoose queries in. I keep getting back:
AssertionError: expected undefined to equal true
Below is the basic template of my test. At the moment I just want to confirm it calles the res.json.
The route returns all entries in the User model
route.js
const User = require('../../../models/users/users');
const listUsers = (req, res) => {
User.find((err, users) => {
if (err) res.send(err);
res.json(users);
})
};
module.exports = listUsers;
test.js
const expect = require('chai').expect;
const sinon = require('sinon');
const listUsers = require('../../../../src/routes/api/users/listUsers');
describe('listUsers', () => {
it('retrieves users', () => {
const req = {};
const res = {};
const spy = res.json = sinon.spy;
listUsers(req, res);
expect(spy.calledOnce).to.equal(true);
})
});
via Mantis
No comments:
Post a Comment