dscape
dscape

Reputation: 2526

QUnit with setup and teardown for async ajax requests

Can someone provide an example of doing a setup/teardown model for async tests ajax requests on qunit?

e.g.

setup: 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

Upvotes: 2

Views: 1855

Answers (2)

Satoshi
Satoshi

Reputation: 74

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 ) {...});

Upvotes: 1

Jörn Zaefferer
Jörn Zaefferer

Reputation: 5705

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.

Upvotes: 4

Related Questions