DEBUG=1 make; bin/gaia-test
suite('Storage()', function() {
test(xxxx);
test(xxxx);
test(xxxx);
});
test('Should xxx ', function() {
xxxx
});
Chai
Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.
Sinon.JS API
Standalone test spies, stubs and mocks for JavaScript. No dependencies, works with any unit testing framework
A test spy is a function that records arguments, return value, the value of this and exception thrown (if any) for all its calls.
A test spy can be an anonymous function or it can wrap an existing function.
When doing so, the original function will behave just as normal but you will have access to data about all calls.
var spy = sinon.spy();
// Creates an anonymous function
var spy = sinon.spy(myFunc);
// Spies on the provided function
var spy = sinon.spy(object, "method");
/* Creates a spy for object.method and
replaces the original method with the spy.
The original method can be restored
by calling object.method.restore(). */
spy.called
Return true if the spy was called at least once
spy.calledOnce
Return true if spy was called exactly once.
More: spy.calledTwice
spy.calledWith(arg1, arg2, ...)
Returns true if spy was called at least once with the provided arguments
Test stubs are functions (spies) with pre-programmed behavior.
They support the full test spy API in addition to methods which can be used to alter the stub’s behavior.
As spies, stubs can be either anonymous, or wrap existing functions.
When wrapping an existing function with a stub, the original function is not called.
var stub = sinon.stub();
// Creates an anonymous stub function
var stub = sinon.stub(object, "method");
//Replaces object.method with a stub function.
//object.method.restore(); (or stub.restore();
var stub = sinon.stub(object, "method", func);
// Replaces object.method with a func, wrapped in a spy.
stub.returns(obj);
// Makes the stub return the provided obj
stub.returnsArg(index);
// stub.returnsArg(0); causes the stub to return the first argument.
stub.throws();
// Causes the stub to throw an exception (Error).
stub.onCall(n);
// stub.onFirstCall(); //stub.onCall(1)
stub.withArgs(arg1[, arg2, ...]);
//Stubs the method only for the provided arguments.
“test_withArgs”:function () {
var callback = sinon.stub();
callback.withArgs(42).returns(1);
callback.withArgs(1).throws("TypeError");
callback(); // No return value, no exception
callback(42); // Returns 1
callback(1); // Throws TypeError
}
"test should stub method with certain argument": function () {
var callback = sinon.stub();
callback.withArgs(42)
.onFirstCall().returns(1)
.onSecondCall().returns(2);
callback.returns(0);
callback(1); // Returns 0
callback(42); // Returns 1
callback(1); // Returns 0
callback(42); // Returns 2
callback(1); // Returns 0
callback(42); // Returns 0
}
Docker Engine, a portable, lightweight runtime
packaging tool
Docker Hub, a cloud service for sharing applications and automating workflows