Mok is a project mainly written in JavaScript, it's free.
Simple mocking library for the narwhal platform
Simple object mocking for tests.
Mock is created by saying:
var mymock = test.mymock(objctToBeMocked);
If 'true' is given as optional parameter, mocking is done recursively.
An example use case might be:
// create mock
var mock = require("mok");
var mymock = mock.mock({foo: function () {}, bar: function () {}});
// lay out the contract before executing tests
mymock.expect.foo().times(1).withParameters('hello').returns(true);
mymock.expect.bar().returns("retval");
mymock.expect.bar().returns("lavter");
// execute tests
func_to_be_tested(foo, bar);
another_func_to_be_tested(bar);
// verify the contract
mock.releaseMocks();
The releaseMocks() function performs the checks that all the right functions were called as many times as they were supposed to. Note that the number of times to be called may either be set explicitly using times() or the mock module may determine it by counting the withParameters() and returns() calls.
mock.expect has following functions: