javascript - Testing ajax requests using jasmine returns TypeError -


Description of work I want to test code that loads a list of resources using $ .get.

Then, source code:

  fetchTemplates: function (list, cb) {var promises = [], $ container = $ ('# template'); Object.edge (list) .for (function (tplSelector) {if ($ (tplSelector). Length> gt; {return;} var promise = $ .get (list [tplSelector]); promise .done (function ( TplHtml); {$ container.append (tplHeit);}) .file (function () {console.warn ('template' '+ tplSelector + "did not match url:" + list [tplSelector]);}); Promises.push (promise);}); Refund $. when. Testing suite ($, promise) .done (cb);}   

test suite:

  This ("true template fitching", function (done) {Var fetchResult = viewManager.fetchTemplates ({'#helpTpl': 'somecorrectaddress'}); fetchResult.done (function () {expect (true) .toBeTruthy (); done ();}); fetchResult.fail (function ) {Hope (false) .toBeTruthy (); done ();});});   

What it generates. Exam passes, but generates an error: TypeError: 'null' is not an object (evaluating 'this.results_.addResult') on jasmine.js? 2348

Then, as the case of trial marked as passed. The suite still generates the above error (and this method is only one sink, trivial to test other parts). My idea was that in the tested system the operations and promises of ASCIC were not properly handled - and thus typeError I added jasmine assic to "deal with the problem" - unfortunately nothing changed. It is also worth noting that if I leave only one exam in the suit using "iit" - no error has arisen. The search was not found in similar cases. Any ideas?

After you 'waitsFor ()' with your run async call 'run' () Read. I have never worked with jquery, but try something like the following in your function:

  var done = false; Var = this; Runs (function () {// your ASCNC test goes here that: don = true;}); Waits (function () {that.done;}, "async code fail", 2000);    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -