0

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
Monica Raj
  • 33
  • 3

1 Answers1

0

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
}
Raph117
  • 3,441
  • 7
  • 29
  • 50
  • Hi , thanks for your response . I m adding the refactored functions as test steps , and reuse the whole test case altogether . – Monica Raj Sep 22 '20 at 07:39
  • For example : I have a login test case , which I might need in every suite at the start of execution. I dont want to copy paste the same test case in every test suite . I simply want to reduce the code weight by reusing the test cases itself , instead of just the functions. – Monica Raj Sep 22 '20 at 07:40
  • test suite1.js test suite2.js test suite3.js test suite4.js , each suite is in a different file. I would like to define login test case in a different file , and use this test case ( it block ) in all the 4 test suites. – Monica Raj Sep 22 '20 at 07:47