Skip to content
Advertisement

node.js mocha before function runs after test execution

I have moved this around so much and tried with done(), asyncand chaining then(), moving the describe() around and my latest attempt was to return a promise in the before as Async function in mocha before() is alway finished before it() spec? suggested.

The console.log('finished!') that indicates the tables have been created is printed way after console.log('starting tests') that indicates the start of the tests.

I should mention that somehow the user table is created and all the user tests works like a charm.

All of my tests fail because they try to perform operations on tables that does not exist. I am not sure of much anymore. How can I make sure the beforeruns before the actual tests?

JavaScript
JavaScript

Edit: Mocha version 8.1.1

Advertisement

Answer

Normally I am not much for answering my own questions – but removing the inner describe block fixed it perfectly. I am yet to figure out exactly why.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement