0
0
Cypresstesting~20 mins

Skipping and focusing tests (.skip, .only) in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cypress Skip & Only Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the test execution result?
Consider this Cypress test code snippet:
describe('Suite A', () => {
  it('Test 1', () => {
    cy.log('Running Test 1')
  })

  it.skip('Test 2', () => {
    cy.log('Running Test 2')
  })

  it('Test 3', () => {
    cy.log('Running Test 3')
  })
})

Which tests will run when this suite executes?
Cypress
describe('Suite A', () => {
  it('Test 1', () => {
    cy.log('Running Test 1')
  })

  it.skip('Test 2', () => {
    cy.log('Running Test 2')
  })

  it('Test 3', () => {
    cy.log('Running Test 3')
  })
})
AOnly Test 2 runs; Test 1 and Test 3 are skipped.
BAll three tests run.
CTest 1 and Test 3 run; Test 2 is skipped.
DNo tests run because of the skip.
Attempts:
2 left
💡 Hint
Remember that .skip prevents that specific test from running.
Predict Output
intermediate
2:00remaining
Which tests run with .only?
Given this Cypress test suite:
describe('Suite B', () => {
  it('Test A', () => {
    cy.log('Running Test A')
  })

  it.only('Test B', () => {
    cy.log('Running Test B')
  })

  it('Test C', () => {
    cy.log('Running Test C')
  })
})

Which tests will execute?
Cypress
describe('Suite B', () => {
  it('Test A', () => {
    cy.log('Running Test A')
  })

  it.only('Test B', () => {
    cy.log('Running Test B')
  })

  it('Test C', () => {
    cy.log('Running Test C')
  })
})
AOnly Test B runs; Test A and Test C are skipped.
BAll tests run because .only does not affect execution.
CTest A and Test C run; Test B is skipped.
DNo tests run because .only disables all tests.
Attempts:
2 left
💡 Hint
Think about how .only focuses on a single test.
assertion
advanced
2:00remaining
Which assertion correctly verifies a skipped test?
You want to write a test that confirms a test marked with .skip does not run.
Which assertion correctly checks that the skipped test's log is NOT present in the Cypress command log?
Acy.get('.command-log').should('not.contain', 'Running Skipped Test')
Bcy.get('.command-log').should('contain', 'Running Skipped Test')
Ccy.get('.command-log').should('have.length', 0)
Dcy.get('.command-log').should('exist')
Attempts:
2 left
💡 Hint
Skipped tests do not produce logs, so the log text should be absent.
framework
advanced
2:00remaining
What happens if multiple tests use .only in Cypress?
In a Cypress test file, two tests are marked with .only:
it.only('Test 1', () => { cy.log('Test 1') })
it.only('Test 2', () => { cy.log('Test 2') })

What will Cypress do when running this file?
Cypress
it.only('Test 1', () => { cy.log('Test 1') })
it.only('Test 2', () => { cy.log('Test 2') })
AOnly Test 1 runs; Test 2 is skipped.
BOnly Test 2 runs; Test 1 is skipped.
CNo tests run because multiple .only cause an error.
DBoth Test 1 and Test 2 run; all other tests are skipped.
Attempts:
2 left
💡 Hint
Check how Cypress handles multiple .only tests.
🧠 Conceptual
expert
2:00remaining
Why should you avoid committing .only in your Cypress tests?
What is the main risk of accidentally committing Cypress tests with .only to your shared code repository?
AIt disables all tests, causing the suite to pass without running anything.
BIt causes only the focused tests to run, skipping all others, which may hide test failures.
CIt causes all tests to run twice, slowing down the suite.
DIt automatically fixes flaky tests, which can mask real issues.
Attempts:
2 left
💡 Hint
Think about how .only changes which tests run.