javascript - Jasmine async call trouble -


i getting started jasmine unit testing , running trouble testing async calls.

i have ajax call trying test, , tried in console know works how want to. think testing same thing did in console wrong.

here console:

> mg = new mandellmvc() mandellmvc {getsessionid: function, setsessionid: function, isvalidgetfunction: function, geturlprefix: function, seturlprefix: function…} > mg.setuselocaldata(true); true > var log = new log(73936780) undefined > log.setlogtype('proc') true > log.fetch(mg, function(){console.log('done');}) true done 

set local data changes between sending http request external server, or loading data local file.

the jasmine test code here:

describe("log model", function() {      var mg = new mandellmvc();     mg.setuselocaldata(true);      var log;      beforeeach(function() {         log = new log(73936780);     });      describe("function fetch", function() {          it("returns false if log type invalid", function() {             expect(log.fetch(mg, function(){})).tobefalsy();         });          // not sure why needs here too?         log = new log(73936780);         log.setlogtype('proc');          it("should make real ajax request", function() {             var callback = jasmine.createspy();             log.fetch(mg, callback);             waitsfor(function() {                 return callback.callcount > 0;             });             runs(function() {                 expect(callback).tohavebeencalled();             });         });     }); }); 

the first test passes. second 1 gives error timeout: timed out after 5000 msec waiting happen. tried follow tutorial apparently not well.

thank you, appreciated!

i think mixing declaration of log = new log(73936780)

the correct code should be

describe("log model", function() {     var mg;     var log;      beforeeach(function() {         mg = new mandellmvc();         mg.setuselocaldata(true);          log = new log(73936780);         log.setlogtype('proc');     });      aftereach(function() {         delete mg;         delete log;     });      describe("function fetch", function() {         it("returns false if log type invalid", function() {             expect(log.fetch(mg, function(){})).tobefalsy();         });          it("should make real ajax request", function() {             var callback = jasmine.createspy();             log.fetch(mg, callback);             waitsfor(function() {                 return callback.callcount > 0;             });             runs(function() {                 expect(callback).tohavebeencalled();             });         });     }); }); 

additionally should check in firebug if request sent , response received correctly


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -