Can someone provide an example of doing a setup/teardown model for async tests ajax requests on qunit?
e.g.
se开发者_Go百科tup: create database t1: REST call to create document 1 t2: REST call to update document 1 t3: REST call to delete document 1 t4: REST call to update document 1 (error cause 1 has been deleted) t5: REST call to create document 2 teardown: clear all documents, delete database
Thanks
QUnit setup/teardown methods can also use stop() and start().
On the other hand, to test clientside code, considering mocking the actual requests. As you tagged with jquery, you're probably using $.ajax and its siblings, so jquery-mockjax should do the job.
start() and stop() is marked as deprecated in QUnit 2.X.
Using module hooks with assert argument can avoid using those deprecated method.
QUnit.module("module", {
beforeEach:function(assert){
var done = assert.async();
setTimeout(function(){ // silly example
done();
}, 5000);
},
afterEach:function(assert){
// same as beforeEach
}
});
QUnit.test( "test", function( assert ) {...});
精彩评论