What is the primary difference between 'beforeEach' and 'beforeAll' hooks in Mocha?

  • beforeEach runs once before all test cases, while beforeAll runs before each test case.
  • beforeEach runs before each test case, while beforeAll runs once before all test cases.
  • beforeEach runs after each test case, while beforeAll runs once before all test cases.
  • beforeEach runs before each test case and has no equivalent to beforeAll.
In Mocha, the primary difference is that the beforeEach hook runs before each test case, ensuring a clean state for each test, while the beforeAll hook runs once before all test cases. This means that changes made in beforeEach won't persist between test cases, but changes in beforeAll will. The other options are incorrect regarding their behavior.
Add your answer
Loading...

Leave a comment

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