How to call a test case from another test case in mocha?

Mocha does not support calling test case inside another test case. So you can not do something as shown below.

it('testA', () => {
    return doSomethingAsync(objA).then(() => {

it('testB', () => callTestA );

But in JavaScript world we can abstract the testing function outside the test case and call it from inside the test case as shown below.

function testAsync(obj) {
    return doSomethingAsync(obj).then(() => {

it('testA', () => testAsync(objA) );

it('testB', () => testAsync(objB) );

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *