buster.js/sinon有什么像`jasmine.any()`?

Dav*_*lio 4 javascript sinon buster.js

开发一个回调驱动的API,我想表达一个特定的函数,用一组特定的参数和"任何"函数(回调)来调用.

Jasmine可以执行以下操作:

var serviceFunction = jasmine.createSpy();
var functionUnderTest = create(serviceFunction);
var thing = 'arbitrary/thing'

functionUnderTest(thing);
expect(serviceFunction).toHaveBeenCalledWith(thing, jasmine.any(Function));
Run Code Online (Sandbox Code Playgroud)

有sinon/buster.js类似的功能吗?到目前为止,我只测试第一个参数,但我真的想表达在测试中需要回调.

这是我到目前为止:

var serviceFunction = this.spy(); // or `sinon.spy()`
var functionUnderTest = create(serviceFunction);
var thing = 'arbitrary/thing'

functionUnderTest(thing);
assert.calledWith(serviceFunction, thing);
Run Code Online (Sandbox Code Playgroud)

小智 9

你应该看看sinon.match api(http://sinonjs.org/docs/#sinon-match-api)

使用sinon.match.func上面的例子会变成:

var serviceFunction = this.spy(); // or `sinon.spy()`
var functionUnderTest = create(serviceFunction);
var thing = 'arbitrary/thing'

functionUnderTest(thing);
assert.calledWith(thing, sinon.match.func);
Run Code Online (Sandbox Code Playgroud)