mardi 1 septembre 2015

Undefined is not a Function while doing unit testing using mocha and chai

I am using Mocha,Chai and Sequelize ORM to do unit testing on a given API. When I run the following Mocha command

mocha fileName.js -w

I get the following error:

Unhandled rejection TypeError: undefined is not a function 

My unit test code is as follows:

describe('createUser', function () {
it('should create a User', function (done) {
    var values = ({
        body: {
            firstName: "XYZ",
            lastName: "XYZ",
            email_Id: "XYZ@gmail.com",
            age: 24
        }
    });
    user.createUser(values,
        function (response) {
          //Unit Tests written over hear
        });
    done();
  });
});

My API createUser is as follows:

createUser: function (req, res) {
    var param = req.body;
    db.sequelize.sync().then(function () {
     //user refers to the user model 
        user.create(param).then(function (response) {
            return res.json({   //Error for undefined is not a function is occuring here
                success: true,
                UserDetails: response
            });
        }).catch(function (err) {
             return res.json({
                success: false,
                exception: err
            });
        });
    });
  }
}

Can somebody let me know why I am facing this issue?

Aucun commentaire:

Enregistrer un commentaire