Reputation: 298
I'd like to use mockjax with qunit but can't get it to work. Here is a simple test I tried: http://jsfiddle.net/shapeshifta/3YNB2/
asyncTest('Response returns jsonp', function() {
$.mockjax({
url: 'http://search.twitter.com/search.json*',
contentType: 'text/json',
proxy: 'mocks/twitter.json'
});
window.abcdef123456 = function() {
start();
ok(true, 'JSONP Callback executed');
};
$.ajax({
url: 'http://search.twitter.com/search.json?q=Javascript&callback=?',
jsonpCallback: 'abcdef123456',
dataType: 'jsonp',
error: function() {},
complete: function() {}
});
$.mockjaxClear();
});
Works like a charm without the mockjax code but does not really work with it... Am I doing soemthing wrong? Tried to use sinon.js but it has some issues with asynchronous test so I wanted to switch to mockjax. But my code just keeps asking twitter for data although mockjax should mock my request...
Any ideas?
Upvotes: 2
Views: 1986
Reputation: 5630
I got this working:
asyncTest('Response returns jsonp', function() { $.mockjax({ url: 'http://search.twitter.com/search.json*', contentType: 'text/json', proxy: 'mocks/twitter.json' }); function onSucceed(data) { start(); ok(true, 'JSONP completed'); }; $.ajax({ url: 'http://search.twitter.com/search.json?q=Javascript&callback=?', dataType: 'jsonp', success: onSucceed, error: function() { alert('error'); }, complete: function() { $.mockjaxClear(); } }); });
Upvotes: 1