Tuesday 16 May 2017

Mocha Thinks Resolution method is overspecified. Specify a callback *or* return a Promise; not both

This is my first day with TDD.

var mongoose = require("mongoose"),
    should = require('should'),
    User = require("app/models/user");

mongoose.connect('mongodb://localhost/altor-security');

describe('user data', function() {
  it('password should be different after changing password', function(done) {
    var old_password_hash,
        new_password = "12345678";

    return User.findOne({ email: "example@gmail.com" }).exec()
    .then(function(user) {
      old_password_hash = user.password;
      return User.findOneAndUpdate({ _id : user._id }, { password: new_password }, { new: true }).exec();
    })
    .then(function(user) {
      user.password.should.not.equal(old_password_hash);
      done();
    })
    .catch(function(err) {
      err.should.equal(null);
      done();
    })
  });
})

My test fails because it thinks that User.findOneAndUpdate method is over specified. But it does take three parameters, findCommand, update, and options.

Any ideas why it's failing though?

Thanks



via Jack Robson

No comments:

Post a Comment