Search code examples
qunit

Qunit test fail in async call


example :
test("An async test", function(){
   stop();
   expect(1);
    model.save( {} , {
          success : function(model,resp){
            ok(model.get('id') != null, "Got id");
                start();
          }
    });    
});

it gives me an error Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.


Solution

  • Could this be because your ajax call throws an error?

    If it did, it would never "succeed" and do an assertion, and it would never call start().

    I suggest moving your assertion and your start() to a "complete" block instead. Complete is ALWAYS called, if the ajax was successful or in error.

    Alternatively you could register an assertion and a start() in an "error" block