0

此代码使我的 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)

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

4

1 回答 1

3

它在那里说,你之前没有返回任何东西,你只是done用来指定任务何时完成。现在您正在返回一个Promise(我假设是 mockgoose 调用的结果),这让 mocha 感到困惑。

于 2017-04-09T23:58:03.193 回答