Reputation: 9175
Aren't these 2 identical?
// ONE
describe('something', () => {
const someConst = 'yes'
it('should do something', () => {
// doing something
})
it('should do something else', () => {
// doing something else
})
})
// TWO
describe('something', () => {
let someNotConst
before(() => {
someNotConst = 'yes'
})
it('should do something', () => {
// doing something
})
it('should do something else', () => {
// doing something else
})
})
This is a contrived example to demonstrate what I mean on a general level.
Upvotes: 1
Views: 25
Reputation: 5339
My guess is simple : in the first case, you are blocking the thread. In the second, you can take advantage of promises (and async/await) in order to do asynchronous operations easily :)
Another important thing is that Mocha can decide to do things between initializing your tests and running it, or do things even before the initialization. This may be important in future versions for compatibility.
Finally, they also provide support for extended error handling, so that you can spot problems faster and solve them quicker.
Could you elaborate on what you mean by "blocking the thread"?
Blocking the thread means you force the engine to do things synchronously, one operation after the other. If you have two lengthy operations, like reading a big file and initializing a database, you have to do both one after the other, and waste time.
In the other case, you can do such a thing, which will run them in parallel and wait for both operations before starting the tests :
before(() => {
let p1 = readEnormousLogFile();
let p2 = initDatabaseWithAThousandTables();
return Promise.all([p1, p2]);
});
Upvotes: 2