Sinon stub callsFake argument

I had the following stubs working fine before

sinon.stub(console, 'log', () => {
    // Check what the arguments holds 
    // And either console.info it or do nothing
});

For example, adding console.info(arguments)inside will show me what happened console.log.

With the version, 2xxI switched to callsFake:

sinon.stub(console, 'log').callsFake(() => {
    // Check what the arguments holds
    // And either console.info it or do nothing
});

Now it works longer. console.info(arguments)it has a bazaar value and has nothing to do with what goes through console.log.

What am I doing wrong?!

+6
source share
1 answer

The arrow function passed in callsFakedoes not receive the object arguments, as you would normally expect in a regular function.

From MDN

, , , , new.target.

(function() {...}), , :

sinon.stub(console, 'log')
console.log.callsFake((...args) => {
  console.info(args)
});
0

Source: https://habr.com/ru/post/1017371/


All Articles