JavaDeveloper
JavaDeveloper

Reputation: 5660

How to stub a method of an object with specified params?

var stub = sinon.stub(object, "method");

Sinon tutorial explains stub but it, how to modify the above line to invoke/stub 'method' with a specified 'param' else do not stub it.

Upvotes: 0

Views: 145

Answers (1)

Arun Kumar Mohan
Arun Kumar Mohan

Reputation: 11905

You can use stub.withArgs to stub a method with the expected arguments.

const stub = sinon.stub(object, 'method');
stub.withArgs(42).returns(1);
stub.withArgs(1).throws('BOOM!');

Upvotes: 5

Related Questions