I m fairly new to mocha framework , I would like to know if we can reuse a test case from a particular describe block.

For example
//Test.js
describe("Reuse code here" , function(){

it("Want to reuse this test case " , function () {
    //do some test here .

})
})

//test1.js
in test1.js can I access the it block of test.js
1

There are 1 best solutions below

3
On

Could you not just refactor the function being passed to the it into its own function?

E.g For example

//Test.js
describe("Reuse code here" , function(){

    it("Want to reuse this test case " , customReusableFunction)
    
})


function customReusableFunction(){
  // do stuff here
}