EKet
EKet

Reputation: 7314

Qunit - Assert the arguments of a function are valid

Problem:
I am trying to check whether the arguments of a function are valid in terms of type and whether they're defined/null to make sure the arguments aren't going to cause issues. I would then want to push different values to these arguments to test the outcomes are as expected.d

Questions

What's the best way to do this in QUnit?

What I've tried

Not much, can't seem to get the arguments of a function as an option for QUnit functions.

Thanks!

Upvotes: 1

Views: 295

Answers (1)

gustavohenke
gustavohenke

Reputation: 41440

You can do that with ease using Sinon.

An quick example:

var spy = sinon.spy();
functionWithCallback( spy );

ok(
  spy.calledWithMatch( sinon.match.object, sinon.match.array ),
  "will be called with object and array"
);

Upvotes: 1

Related Questions