cypress

before hook is called twice in Cypress.io test


For some reason, the hook before is called twice. It works well without cy. calls. Before a test case with cy. logic it calls the hook at the second. This is a trivial error that I have been resolving for a week.


Solution

  • In our project the root cause was because we used the e2e.js file to add hookers and utils functions. For every test when importing the utils functions the hooks got imported as well. Since e2e.js is imported by default, the hooks got executed twice.

    If the same applies to you, just move the utils functions out of e2e.js, update the imports in the tests and keep only the hooks in e2e.js file.