你差点通过考试。对于这种测试,我们可以使用
calledWith
从sinon检查函数和参数是否被正确调用。
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(),
};
authController.registration(req, res);
// this is how we check that the res is being called with correct arguments
expect(res.status.calledWith(201)).to.be.ok;
expect(res.json.calledWith({ user: USER })).to.be.ok;
});
});
希望有帮助。