• 0

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(() => {
        expect();
    });
});

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(() => {
        expect();
    });
}

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

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