Graviton
Graviton

Reputation: 83244

JQuery Mocking

I am looking for a mature framework that can do Javascript mocking, especially on AJAX and JSON area.

Is there any existing mocking framework for Javascript ( and/ or JQuery) that you are used and can recommend?

Edit: I have evaluated jqmock and jqunit. It seems that it's the only framework that can do basic library mocking and stubbing, but it can't do AJAX call.

Upvotes: 13

Views: 7692

Answers (3)

bert bruynooghe
bert bruynooghe

Reputation: 3093

Mocking is included in the jasmine testframework too. I used it myself to mock out jQuery.ajax:

spyOn(jQuery, 'ajax').andCallFake(function(value) {
    value.success(data);
});

Upvotes: 2

jitter
jitter

Reputation: 54605

Here are some links that might help you:

amok (claims to have ajax support)

fakequery

QUnit

JSMock

qMock

jqunit + jqmock


Other javascript testing "frameworks"

jqunit

Jack

YUI Test

JSSpec

Upvotes: 16

August Lilleaas
August Lilleaas

Reputation: 54593

I prefer modular code. Modular code is easy to mock!

var function fetchAjaxData(){
  // Perform ajax request.
  // Call 'update' with the data in question.
}

var update = function(ajaxData){
  // do things with ajaxData
}

With this kind of code, all you need to do is to call the 'update' function to mock a ajax request.

Upvotes: 4

Related Questions