DailyJS

qmock

2010-02-01 00:00:00 +0000 by Alex R. Young

qmock is an expect-run-verify JavaScript mocking library. You can use it to mock objects alongside
another testing library.

People generally mock IO-bound services, like network or disk access.
The authors suggest that you could use qmock to mock Ajax calls. There's
a note about this in the API
documentation
:

mock$ = new Mock();

mock$
        .expects(1)
                .method('get')
        .withArguments('some/url', Function)
        .callFunctionWith('data response');

// Exercise
var called = false;
mock$.get('some/url', function (data) { called = true });

As this example illustrates, qmock has an API that relies on cascading
invocations. This helps the API appear expressive.

There's some interesting history behind qmock:

qMock was written during our (Mark Meyer // Andy Beeching) tenure at Channel 4 Television, in response for the project requirement of automated testing of all JavaScript code on the site (using QUnit as our test harness). We are grateful to them for allowing us to open-source the project.