函数前的 Mocha - 没有花括号错误的 lambda;带花括号的 lambda 有效

Mocha before function - lambda without curly braces errors; lambda with curly braces works

此代码使我的 mocha 测试无误通过:

before(done => {
  mockgoose
    .prepareStorage()
    .then(() => mongoose.connect('mongodb://example.com/TestingDB'))
    .then(done)
})

it('passes', done => done())

但是删除 before 块中的大括号会导致错误:

before(done =>
  mockgoose
    .prepareStorage()
    .then(() => mongoose.connect('mongodb://example.com/TestingDB'))
    .then(done)
)

it('passes', done => done())

1) "before all" hook

0 passing (2s)
1 failing

1)  "before all" hook:
    Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both.
    at process._tickCallback (internal/process/next_tick.js:109:7)

有谁知道为什么?如果需要更多上下文,我可以帮忙。

它就在那里说,你之前没有返回任何东西,你只是使用 done 来指定任务何时完成。现在你返回一个 Promise(我假设是 mockgoose 调用的结果)并且它令人困惑 mocha。