Any suggestions on testing async ajax?

1 view
Skip to first unread message

Zac Tolley

unread,
Aug 12, 2009, 12:48:12 PM8/12/09
to Dr Nic's JavaScript projects
I need to test a library that does ajax calls, and gives you the usual
thing of a method that lets you pass a url and references to functions
to call when it goes good or bad, i.e.

ajax.request(url,success,failure);

I somehow want to test this though, if possible have he call to ajax
within the scope of a test and also when it calls a success or fail
function I want to run some asserts on the resulting data.

I even tried creating a new test run inside a success function, ala:

var success = function(result) {

new Test.Unit.Runner({
setup: function() {},
teardown: function() {},
testGoodAjaxCall : function() { with(this) {
assert(result.length > 0, true);
}},
});

};

but the test page just saying running.

Any suggestions?

sky

unread,
Aug 20, 2009, 1:57:16 AM8/20/09
to Dr Nic's JavaScript projects
I won't address the requirement of a self contained request/test
object. Smells like going in the out door to me.

What I can do is point you to a simple async testing pattern that has
worked well for me. Your mileage may vary.

http://skysanders.net/subtext/archive/2009/08/19/jsunittest-async-test-pattern.aspx

best regards,
Sky Sanders

Sky Sanders

unread,
Aug 20, 2009, 1:46:32 AM8/20/09
to drnic-javasc...@googlegroups.com
I won't address the requirement of a self contained request/test object. Smells like going in the out door to me.
 
What I can do is point you to a simple async testing pattern that has worked well for me. Your mileage may vary.
 
 
best regards,
Sky Sanders

Reply all
Reply to author
Forward
0 new messages