Ask Your Question
0

How can we pass arguments through a Sinon stub?

asked 2021-11-27 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-10-01 03:00:00 +0000

david gravatar image

To pass arguments through a Sinon stub, you can use the callsFake method along with an anonymous function that takes arguments.

Example:

const myStub = sinon.stub();
myStub.callsFake((arg1, arg2) => {
  // do something with arg1 and arg2
});

Then, when you call myStub with arguments, the anonymous function will be called with those arguments.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-11-27 11:00:00 +0000

Seen: 15 times

Last updated: Oct 01 '22