【发布时间】:2017-05-15 08:50:41
【问题描述】:
我正在尝试测试我的 RESTful nodejs API,但一直遇到以下错误。
Uncaught TypeError: Cannot read property 'should' of undefined
我正在为我的 API 使用 restify 框架。
'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();
});
});
});
});
当我删除res.body.should.be.a('array'); 行时,测试工作正常
无论如何我可以解决这个问题吗?
【问题讨论】: