之前我有完整的以下存根
sinon.stub(console, 'log', () => {
// Check what the arguments holds
// And either console.info it or do nothing
});
Run Code Online (Sandbox Code Playgroud)
例如,console.info(arguments)在里面添加,会告诉我任何事情console.log.
随着版本2xxI切换到callsFake:
sinon.stub(console, 'log').callsFake(() => {
// Check what the arguments holds
// And either console.info it or do nothing
});
Run Code Online (Sandbox Code Playgroud)
这现在更长的工作.console.info(arguments)有市集价值,与console.log传递无关.
我究竟做错了什么?!
您传递给的箭头函数callsFake不会arguments像通常在常规函数中所期望的那样接收对象。
从MDN
箭头函数表达式的语法比函数表达式短,并且没有自己的this,arguments,super或new.target。
将您的arrow函数更改为常规的匿名函数(function() {...}),或使用传播运算符显式解压缩参数:
sinon.stub(console, 'log')
console.log.callsFake((...args) => {
console.info(args)
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7278 次 |
| 最近记录: |