My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

jqMock is a lightweight javascript Mock Framework for the jqUnit testing framework. jqMock allows functions in dependent functions such as native alert dialogs to be mocked, so that your own code can be tested in isolation.

jqMock has comprehensive expectation support, with complex argument matching criteria, ordered/unordered expectations, multiplicity control, intercepting return values and throwing exceptions.

See the user guide here

Leave a comment on my blog here.

Intercepting

Intercept functions so you can write your unit test in isolation.

jqUnit.test('hello world test', function() {
    var alertMock = new jqMock.Mock(window, 'alert');
    alertMock.modify().args('hello world!').multiplicity(2).returnValue();
    hello();
    hello();
    alertMock.verify();
    alertMock.restore();
});

Better Assertion

jqMock provides an assertion function assertThat which allows you to setup powerful and flexible expectations by providing a comprehensive set of expressions. Even if you do not use this framework for mocking, assertThat is a very useful addition to the jqUnit toolset. For example:

jqMock.assertThat(3,3);
jqMock.assertThat([1,2,3],[1,2,3]);	
jqMock.assertThat({a:'a',b:'b'}, {b:'b', a:'a'});
jqMock.assertThat([1,2,3], is.instanceOf(Array));
jqMock.assertThat('foo', is.anyOf(['foo','bar']));
jqMock.assertThat(myobject, is.allOf([is.instanceOf(MyObject),{x:'x'}]));

Detailed Error Messages

Error messages are clear and explicit, and failures are presented with full details of the satisfaction state.

Powered by Google Project Hosting