0

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.

jmrah
  • 5,715
  • 3
  • 30
  • 37

1 Answers1

3

It says so right there, you weren't returning anything before, you were just using done to specify when the task is done. Now you are returning a Promise (the result of the mockgoose call i'd assume) and it's confusing mocha.

MinusFour
  • 13,913
  • 3
  • 30
  • 39
  • Ahhhh, yes. By using the lambda without curly braces, I there's an implicit return! So by no curly braces, I was returning a Promsie. And by supplying `done`, I was also specifying a callback. I'll just get rid of the `done` and be on my merry way. Thanks! I'm new to this Javascript scene :) – jmrah Apr 10 '17 at 00:03