Testing an MEVN Application Chapter 9
Let's move on to add the functional test part. We will be writing the test for the
/dummy_test method.
In movies.spec.js, let's add the following lines of code:
var controller = require("./../../../controllers/movies.js");
let chaiHttp = require('chai-http');
let chai = require('chai');
var expect = chai.expect;
var should = chai.should();
var express = require("express");
let server = require('./../../../server.js');
var app = express();
chai.use(chaiHttp);
function buildResponse() {
return http_mocks.createResponse({eventEmitter:
require('events').EventEmitter})
}
describe('controllers.movies', function(){
it('exists', function(){
expect(controller).to.exist
})
})
describe('/GET dummy_test', () => {
it('it should respond with a name object', (done) => {
chai.request(server)
.get('/dummy_test')
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.an('object');
done();
});
});
});
In the preceding code, we have added a new package called chai-http, which is used to
mock the request. Let's install this package, as follows:
$ npm install chai-http --save