无法读取未定义的属性'then',bcrypt.hash()

我试图创build一个testing用户,在我需要散列密码的摩卡testingbefore块。 显然,如果使用promise,则不需要done()函数 。 我正在执行bcrypt.hash就像它在bcrypt文档中所说:

 before(function(){ //create a user and populate user's first recipes //create a User object return bcrypt.hash('newt', 10).then(function(err,hash){ //create the user object var user = new User({email:'test@test.io',username:'test',password:hash}) //save that user user.save() }) }) 

但是,当我运行testing时,它给了我一个错误:

TypeError: Cannot read property 'then' of undefined

是什么赋予了? 谢谢。

bcrypt.hash('newt',10)没有返回一个承诺。

确保你在bcrypt和mocha的最新版本,因为这些软件包的早期版本不支持承诺。 你也可以尝试重新安装模块。