Skip to content
Advertisement

Mocha test false assert timeouts

I have some problem with my async mocha tests. The assert method within a promise results in a timeout when the input evaluates to false. (with true values it works fine)

This is a simplified version of the problem. We usually do networking instead of this constructed promise.

JavaScript
JavaScript

Advertisement

Answer

You’d better NOT use async/await syntax on the promise constructor. It’s an anti-pattern.

assert(false) will throw an error, but this error will not be caught by the .catch() method. For more info, see https://stackoverflow.com/a/43050114/6463558

So you should remove the async from the promise constructor. Then, the error which assert(false) threw will be caught.

E.g.

JavaScript

test result:

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