unit testing - Jasmine AJAX mock turns string into array -


i'm trying write test suite around ajaxrequest class, when i'm trying inspect request body test failure

failed tests: ajaxrequest   #post   ✖ attaches body response     phantomjs 1.9.8 (mac os x 0.0.0)   expected object({ example: [ 'text' ] }) equal object({ example: 'text' }). 

here's relevant bit of unit test:

      req = new ajaxrequest().post('http://example.com')             .body({                 example: 'text'             }).run(); 

and here's run() method ajax request made

var options = {         url: this._url,         method: this._method,         type: 'json',         data: this._body     };      return when(reqwest(options)); 

i'm using reqwest issue ajax requests.

could point out why it's expecting ['text'] when request sent 'text' in json body?

thank you!

changing implementation of ajaxrequest solved problem.

here new implementation of run using xmlhttprequest

run () {     var req = new xmlhttprequest();      req.open(this._method, this._url, true);      req.send(json.stringify(this._body));      return when.promise((resolve, reject) => {         req.onload = function() {             if (req.status < 400) {                 var param = req.response;                 try { param = json.parse(param) } catch (e) { };                 resolve(param);             } else {                 reject(new requesterror(req.statustext, req.status));             }         };     }); } 

this not gets rid of library leaves more control on when reject request promise.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -