DailyJS

qmock

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

libraries testing

qmock

Posted by Alex R. Young on .
Featured

libraries testing

qmock

Posted by Alex R. Young on .

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.