Reputation: 2466
I am trying to Stub class property using sinon.
function wrapper() {
this.obj = {"message":"hello"};
this.sendmessege = function() {
console.log(this.obj.message);
return "message is:" + this.obj.message;
}
}
// stub
var wrap = new wrapper();
stub = sinon.stub(wrap , 'sendmessege', function () {
return 'hola';
});
stub1 = sinon.stub(wrap , {'obj':
{'message':'hii'}
});
console.log(stub1);
its giving me
error : Attempted to wrap object property obj as function.
how i can stub obj ?
Upvotes: 6
Views: 7411
Reputation: 950
If you want to stub the property of an object, use the value()
method of the Stub
.
stub1 = sinon.stub(wrap, 'obj').value({message: 'hii'});
Documentation Reference: http://sinonjs.org/releases/v4.1.2/stubs/#stubvaluenewval
Upvotes: 7