I have a controller with method:
registration(req, res) {
if (!req.user) return res.status(401).send('Registration failed');
const { user } = req;
return res.status(201).json({ user });
},
I want to test the registration method which sends the json with my fake data.
const { expect } = require('chai');
const sinon = require('sinon');
const authController = require(...);
describe('authController', () => {
const USER = {
email: 'test@test.com',
password: 'Test12345',
confirm: 'Test12345',
username: 'Test',
};
it('it should send user data with email: test@test.com', () => {
const req = { user: USER };
const res = {
status: sinon.stub().returnsThis(),
json: sinon.spy(),
};
console.log('RES: ', res); // I can't see the json data
authController.registration(req, res);
expect(res.json).to.equal(USER);
});
I checked that my USER's data go into controller (req.user). I tried to look what contains res with spy, but didn't find my USER data I don't understand how to use sinon in my situation?