How can I build my test suite asynchronously?

You should run Mocha with the –delay option, and then use run() once you are done building your test suite. Here is an example derived from the code you show in the question: ‘use strict’; function test() { console.log(1); describe(‘Unit Testing’, () => { console.log(2); it(“test”, () => { console.log(3); }); }); // You must … Read more

How to programmatically skip a test in mocha?

You can skip tests by placing an x in front of the describe or it block, or placing a .skip after it. xit(‘should work’, function (done) {}); describe.skip(‘features’, function() {}); You can also run a single test by placing a .only on the test. for instance describe(‘feature 1’, function() {}); describe.only(‘feature 2’, function() {}); describe(‘feature … Read more

Babel unexpected token import when running mocha tests

For Babel <6 The easiest way to solve this problem is: npm install babel-preset-es2015 –save-dev Add .babelrc to the root of the project with contents: { “presets”: [ “es2015″ ] } Ensure that you are running mocha with the “–compilers js:babel-core/register” parameter. For Babel6/7+ npm install @babel/preset-env –save-dev Add .babelrc to the root of the … Read more

Is there a way to get Chai working with asynchronous Mocha tests?

Your asynchronous test generates an exception, on failed expect()ations, that cannot be captured by it() because the exception is thrown outside of it()‘s scope. The captured exception that you see displayed is captured using process.on(‘uncaughtException’) under node or using window.onerror() in the browser. To fix this issue, you need to capture the exception within the … Read more