您好我是unit
测试的新手。我目前正在使用Mocha,Chai和Sequelize来为API进行TDD单元测试。但是在使用Mocha运行单元测试时,我收到以下错误:
msg: 'TypeError: Cannot read property \'firstName\' of undefined' } to not exist
我为API编写的unit
测试如下:
describe('createUser', function () {
it('should create a User', function (done) {
var email_Id = "xyz@gmail.com";
var firstName = "xyx";
var values = JSON.stringify({
body: {
email_Id: email_Id,
firstName: firstName
}
});
user.createUser(values, function (err, response) {
expect(response).should.be.an(object);
expect(err).to.be.null;
});
done();
});
});
我的API
如下:
createUser: function (req, res) {
var param = req.body;
var firstName = param.firstName;
var email_Id = param.email_Id;
db.sequelize.sync().then(function () {
user.create(param).then(function (response) {
// return a Success Response in JSON format
}).catch(function (err) {
// return an Error Response in JSON format
});
});
}
}
有人可以帮助我,为什么我会收到此错误?