Search code examples
automationautomated-testscypress

Cypress - exclude tests from beforeEach


90% of my tests need to do one task before start so I made beforeEach function that works perfect.

Rest 10% need to do something else before start.

Is in Cypress some way to do beforeEach except some tests?


Solution

  • No, but you can do some tricks with it. For example:

    describe('describe 1', function(){
      beforeEach(function(){
      })
      it('test 1', function(){
      })
      it('test 2', function(){
      })
    })
    
    describe('describe 2', function(){
      beforeEach(function(){
      })
      it('test 3', function(){
      })
    })
    

    This way you still have your tests clustered in 1 file, but by separating them to several describe()'s you can separate the beforeEach()