【发布时间】:2017-10-06 10:22:51
【问题描述】:
我试图监视传递给副作用 ey 函数的所有参数,该函数由接收最终参数的匿名函数容器组成
(其实我想把它存根,但间谍只是一个开始)
classA.js
const classB = require(`classB.js`)
const doWork = ( a, b, c, d, e ) => {
//do things with a, b, c, d, e to make x, y, z…
return classB.thingToSpyOn(a, b, c, x, y)(z) //<=note curry here
}
ClassA.spec.js
const classA = require(`classA.js`)
const classB = require(`classB.js`)
describe(`doWork`, () => {
sinon.spy(classB, 'thingToSpyOn' )
classA.doWork( “foo”, “bar”, “baz”, “bing”, “boing”)
//now i can get the spy to tell me what it received as a, b, c, x, y
console.log(classB.thingToSpyOn.args)
...
但是如何将收到的内容记录为z?
【问题讨论】:
标签: javascript node.js unit-testing sinon partial-application