无法使用Mocha和Chai对sequelize中的API进行单元测试

时间:2015-09-01 04:43:01

标签: unit-testing mocha sequelize.js chai

您好我是unit测试的新手。我目前正在使用MochaChaiSequelize来为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
        });
    });
  }
}

有人可以帮助我,为什么我会收到此错误?

0 个答案:

没有答案