Reputation: 520
In nodejs
I am in an express controller that has the response object doing this as the second statement:
res.set('Content-Type', 'application/json');
When I try to stub it out
sinon.stub(contractorController.putcontractor, 'set').resolves(true);
I get the error
TypeError: Cannot stub non-existent own property
I've tried many things, please help. This controller is being imported with a require statement and the controller itself is a series of exported functions (No classes). I have been able to get this to work when I create classes, but I am not certain I am supposed to be refactoring all this code into classes just so the unit tests will work.
Upvotes: 1
Views: 2192
Reputation: 520
In express while unit testing the req
and res
objects with all their related methods both need to be stubbed.
const res = {
set: sinon.stub(),
get: sinon.stub(),
...
}
Upvotes: 1