Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has buster.js / sinon something like `jasmine.any()`?

Developing a callback-driven API, I would like to express that a certain function as to be called with a specific set of parameters and “any” function (the callback).

Jasmine can do the following:

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

functionUnderTest(thing);
expect(serviceFunction).toHaveBeenCalledWith(thing, jasmine.any(Function));

Have sinon/buster.js similar capabilities? So far I’m testing only the first argument, but I’d really like to express the need for a callback in the test.

This is what I have so far:

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

functionUnderTest(thing);
assert.calledWith(serviceFunction, thing);
like image 355
David Aurelio Avatar asked Jan 13 '23 19:01

David Aurelio


1 Answers

You should check out the sinon.match api (http://sinonjs.org/docs/#sinon-match-api)

Using sinon.match.func your example above would become:

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

functionUnderTest(thing);
assert.calledWith(thing, sinon.match.func);
like image 149
Joe Grund Avatar answered Jan 26 '23 03:01

Joe Grund