Monday, 15 May 2017

How to resolve "Cannot read property 'should' of undefined" in chai?

I'm trying to test my test my RESTful nodejs API but keep running into the following error.

Uncaught TypeError: Cannot read property 'should' of undefined

I'm using the restify framework for my API.

'use strict';

const mongoose = require('mongoose');
const Customer = require('../src/models/customerSchema');

const chai = require('chai');
const chaiHttp = require('chai-http');
const server = require('../src/app');
const should = chai.should();

chai.use(chaiHttp);

describe('Customers', () => {
   describe('/getCustomers', () => {
       it('it should GET all the customers', (done) => {
           chai.request(server)
               .get('/getCustomers')
               .end((err, res) => {
                   res.should.have.status(200);
                   res.body.should.be.a('array');
                   done();
                });
       });
   });
});

The testing works fine when I remove the line res.body.should.be.a('array'); Is there anyway I can fix this problem?



via BattleFrog

No comments:

Post a Comment