Sunday, 9 April 2017

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

This code makes my mocha tests pass without error:

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

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

But removing the curly braces in the before block causes the error:

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)

Does anyone know why? If more context is needed, I can oblige.



via jrahhali

No comments:

Post a Comment