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 }); }
Comments
Post a Comment