Wednesday, 12 April 2017

Unit Test passes without check Node.js

I am using Node.js (noob in BDD). In my controller I have a function like so:

  var getUser = function(username, done) {
    console.log('prints');
    User.findOne({
      'local.username': username
    }, function (err, user) {
      console.log('doesn"t print');
      if (err) {
        return done('Oops, server error!', null);
      } else {
        return done(null, user);
      }
    });
  };

I am using Mocha and described a test block like so:

  describe('can be created only using a web interface', function () {
    describe('The user name should:', function () {
      it("not already exist in the database", function(done){
        userController.getUser('my@email.com', function(err, user){
          console.log('doesn"t print');
        });
      });
    });
  });

It seems like User.findOne is not working the way I expect it to since the test passes no matter what and the code inside doesn't even get executed. What am I missing?

NB: Calling the same function in other parts of the code works just fine.



via Rahul Soni

No comments:

Post a Comment