} Now, I try to use "mocha" to unit test this line of newly added code using MOCHA: request = require('request'); should = require('should'); describe('GET /core/dbq/534e930204dd311822ec1c9d', function() { this.timeout(15000); it ('Check header message', function(done) { request.get('http://localhost:3001/ecrud/v1/core/dbq/534e930204dd311822ec1c9d', function(err, response, header) { response.statusCode.should.equal(200); //This line passes the MOCHA test response.warning.should.equal('my_customized_message'); // Uncaught TypeError: Cannot read property 'should' of undefined done(); } ) } ) } ) If I test the response.statusCode only, there is no problem. The MOCHA test passes successfully. But, if I test the response.warning, I get an error saying the property 'should' is not defined ( I have run npm should --save-dev). It looks that "warning" is not a field of the "response". The same error happens if I try to test the response.contentType. I thought "Content-Type" is a very well known response header. Anyway, what I am really interested in is to test the "Warning" header. Please help. Thank you. |
request = require('request');should = require('should');describe('GET /core/dbq/534e930204dd311822ec1c9d', function() {
this.timeout(15000);
it ('Check header message', function(done) {
request.get('http://localhost:3001/ecrud/v1/core/dbq/534e930204dd311822ec1c9d', function(err, response, header) {
response.statusCode.should.equal(200); //This line passes the MOCHA test
response.warning.should.equal('my_customized_message'); // Uncaught TypeError: Cannot read property 'should' of undefined
done();
} )
} )
} )
If I test the response.statusCode only, there is no problem. The MOCHA test passes successfully. But, if I test the response.warning, I get an error saying the property 'should' is not defined ( I have run npm should --save-dev). It looks that "warning" is not a field of the "response".The same error happens if I try to test the response.contentType. I thought "Content-Type" is a very well known response header. Anyway, what I am really interested in is to test the "Warning" header. Please help. Thank you.
Thank you very much for your explanation. I have learned a lot. The code is working now. I am going to learn supertest.
I have a code snippet of MOCHA that tests the response headers. The code (below) works.
request = require('request');
should = require('should');
describe('GET /core/dbq/534e930204dd311822ec1c9d', function() {
this.timeout(15000);
it ('Check header message', function(done) {
request.get('http://localhost:3001/ecrud/v1/core/dbq/534e930204dd311822ec1c9d', function(err, response, body) {
response.statusCode.should.equal(200);
response.headers.warning.should.equal('100 Max Record Limit Exceeded');
done();
} )
} )
} )
I am trying to do the same thing using the SuperTest. I worked on the code for quite a while and managed to make the code bug free. But, my code does not seem to do any comparison of the "expected" response to the "actual" response -- I got 0 passing (0ms) on the console. I cannot figure out where the problem is. Therefore, I post my code below for advices. Thank you.
var express = require('express');
var request = require('supertest');
var app = require('../bin/server.js');
module.exports = exports = function(request) {
describe('GET /core/dbq/534e930204dd311822ec1c9d', function() {
this.timeout(15000);
it ('Check header message', function(done) {
request(app)
.get('http://localhost:3001/ecrud/v1/core/dbq/534e930204dd311822ec1c9d')
.expect(status, 200)
.expect('warning', '100 Max Record Limit Exceeded')
.end(function(err, res) {
if (err) return done(err);
done()
});
} );
} )
}
--
You received this message because you are subscribed to a topic in the Google Groups "Mocha" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mochajs/4D4Dly0uPn0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mochajs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.