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

377
April 10, 2017, at 11:38 AM

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.

Answer 1

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.

Rent Charter Buses Company
READ ALSO
OpenCV accident detection with nodeJS (Intel Edison)

OpenCV accident detection with nodeJS (Intel Edison)

I have a project where I have to use Opencv camera to detect car accidents, using nodeJs or java code or pyhton to monitor dataI also have to make sure the camera and the board (Intel Edison) both are configured to same IP Address

397
Is it fine to assign express js application instance to global scope?

Is it fine to assign express js application instance to global scope?

I am making my own node js structure and i am using express for http serverI also saw few other structures like loopback and sails

310