0
0
Cypresstesting~5 mins

Skipping and focusing tests (.skip, .only) in Cypress

Choose your learning style9 modes available
Introduction

Sometimes you want to run only some tests or skip others to save time or focus on a problem. Cypress lets you do this easily.

You want to skip a test that is broken temporarily.
You want to run only one test to debug it quickly.
You want to skip a group of tests that are not relevant now.
You want to focus on a specific test case during development.
You want to avoid running slow tests while working on fast feedback.
Syntax
Cypress
it.skip('test name', () => { ... })
it.only('test name', () => { ... })
describe.skip('group name', () => { ... })
describe.only('group name', () => { ... })

.skip tells Cypress to ignore that test or group.

.only tells Cypress to run only that test or group and skip others.

Examples
This test will be skipped and not run.
Cypress
it.skip('does not run this test', () => {
  cy.visit('/home')
  cy.contains('Welcome')
})
Only this test will run, all others will be skipped.
Cypress
it.only('runs only this test', () => {
  cy.visit('/login')
  cy.get('input').type('user')
})
All tests inside this group will be skipped.
Cypress
describe.skip('skip this group', () => {
  it('test 1', () => {})
  it('test 2', () => {})
})
Only tests inside this group will run.
Cypress
describe.only('run only this group', () => {
  it('test 1', () => {})
  it('test 2', () => {})
})
Sample Program

This suite has three tests. The second test is skipped. The third test is focused with .only, so only it runs.

Cypress
describe('My Test Suite', () => {
  it('test 1 runs normally', () => {
    cy.wrap(true).should('be.true')
  })

  it.skip('test 2 is skipped', () => {
    cy.wrap(false).should('be.true')
  })

  it.only('test 3 runs only this test', () => {
    cy.wrap(5).should('equal', 5)
  })
})
OutputSuccess
Important Notes

Using .only anywhere will cause Cypress to run only those tests or groups marked with it.

Be careful to remove .only before final test runs to avoid missing tests.

.skip is useful to temporarily disable flaky or incomplete tests.

Summary

.skip skips tests or groups so they don't run.

.only runs only the marked tests or groups, skipping all others.

These help focus testing and save time during development.