node.js - Node Jasmine 2.0 and multiple conditions -


jasmine has funky methodology of not halting @ first failure within test. fine in general, doesn't come without issues. i'm wondering best practice scenario such this:

it('should process async results nicely', function (done) {     this.getjson('something', function(response) {         expect(response.status).toequal('ok');         expect(response.data).tobedefined();         expect(response.data.length).toequal(5);         done();     } } 

the problem here crash whole test suite if response.data undefined. again, writing conditionals within test case frowned upon. have other choice scenario? given async nature of of tests, common issue.

maybe trick:

it("should make real ajax request", function () {     var callback = jasmine.createspy();     makeajaxcall(callback);     waitsfor(function() {         return callback.callcount > 0;     }, "the ajax call timed out.", 5000);      runs(function() {         expect(callback).tohavebeencalled();     }); });  function makeajaxcall(callback) {     $.ajax({         type: "get",         url: "data.json",         contenttype: "application/json; charset=utf-8"         datatype: "json",         success: callback     }); } 

source: http://www.htmlgoodies.com/beyond/javascript/test-asynchronous-methods-using-the-jasmine-runs-and-waitfor-methods.html#fbid=-1pvhtwm6xy


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -