Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 无法使用Mocha和Chai在sequelize中对API进行单元测试_Unit Testing_Mocha.js_Sequelize.js_Chai - Fatal编程技术网

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

Unit testing 无法使用Mocha和Chai在sequelize中对API进行单元测试,unit-testing,mocha.js,sequelize.js,chai,Unit Testing,Mocha.js,Sequelize.js,Chai,您好,我是新来的单元测试。我目前正在为一个API进行TDD单元测试。但是,在使用运行单元测试时,出现以下错误: msg: 'TypeError: Cannot read property \'firstName\' of undefined' } to not exist 我为API编写的单元测试如下所示: describe('createUser', function () { it('should create a User', function (done) { var ema

您好,我是新来的
单元
测试。我目前正在为一个API进行TDD单元测试。但是,在使用运行单元测试时,出现以下错误:

 msg: 'TypeError: Cannot read property \'firstName\' of undefined' } to not exist
我为API编写的
单元测试如下所示:

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();
   });
});
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
        });
    });
  }
}
我的
API
如下:

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();
   });
});
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
        });
    });
  }
}

有人能帮我解释一下为什么会出现这个错误吗?

req.body未定义