QUnit example
A simple example of QUnit tests using JSFiddle
HTML
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<script src="//sinonjs.org/releases/sinon-1.14.1.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
JavaScript
var sut = {
ImportantFunction: function(dependency){
dependency("a", 1);
dependency("b", 2);
}
};
sinon.assert.pass= function(assertion){
ok(true, assertion); //just to show a sinon.assert was run when the test is green
};
test("dependency was called as expected", function () {
var dependencyStub = sinon.stub();
sut.ImportantFunction(dependencyStub);
ok(dependencyStub.calledTwice, "dependency was called twice");
sinon.assert.calledWith(dependencyStub, "a", 1);
sinon.assert.calledWith(dependencyStub, "b", 2);
//when failed it wont show any information about why it failed
ok(dependencyStub.firstCall.calledWith("a", 1));
ok(dependencyStub.secondCall.calledWith("b", 2));
//when failed you will know the arguments were not as expected but you want know the actual ones (and the expected have to be manually maintained in the error message)
ok(dependencyStub.firstCall.calledWith("a", 1), "dependency called with expected args 'a', 1");
ok(dependencyStub.secondCall.calledWith("b", 2), "dependency called with expected args 'b', 2");
});