【发布时间】:2015-04-04 00:54:12
【问题描述】:
我尝试使用 mocha 框架测试我的 MongoDB Mangoose 模型的验证。
describe 'User', ->
describe 'create', ->
it 'should reject a user with an already existing mail', (done) ->
User.create
mail: "minimal@gmail.com"
, (err) ->
if err then done() else done(false)
我预计 Mongoose 会出现验证错误,因为该邮件已被占用,但该字段被标记为唯一。
如何测试特定错误?我认为最干净的方法是使用should.throws(callback, message-regexp),但是,这不起作用,因为 Model#create 是异步的。
参考资料(对我没有帮助)
【问题讨论】:
标签: node.js asynchronous mongoose mocha.js