mercredi 1 avril 2015

Test form data using Mocha for NodeJS

i am trying to write a mocha test for nodejs that sends form data and checks if the response is ok (200), and that res.body has some properties, but the test fails and i dont know the reason. increasing the timout didnt help, when i use AdvancedRESTclient chrome extension with the form data in the Payload section its works perfectly! the .type('form') is supposed to be superagent syntax



var should = require('should'),
assert = require('assert'),
request = require('supertest'),
superagent = require('superagent');

describe('Data', function () {

it('should return status OK (200)', function(done) {
this.timeout(20000);
request.post('http://xxx:3000/xxx/xxx')
.type('form')
.send({startDate:"2015-03-08",endDate:"2015-03-24",timeLapse:"day"})
.end(function(err, res) {
if (err) {
throw err;
}
assert.ok(res);
assert.ok(res.body);
assert.equal(res.status, 200);
res.body.should.have.property('trial');
done();
});
});


and the error is:



TypeError: undefined is not a function
at Context.<anonymous> (C:\Users\user\WebstormProjects\StatsTest\test\getMostRecentData.js:112:17)
at Test.Runnable.run (C:\Users\user\AppData\Roaming\npm\node_modules\mocha\lib\runnable.js:233:15)
at Runner.runTest (C:\Users\user\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:387:10)
at C:\Users\user\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:470:12
at next (C:\Users\user\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:312:14)
at C:\Users\user\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:322:7
at next (C:\Users\user\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:257:23)
at Immediate._onImmediate (C:\Users\user\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:289:5)
at processImmediate [as _immediateCallback] (timers.js:358:17)

Aucun commentaire:

Enregistrer un commentaire