Bird
Raised Fist0
Cypresstesting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the .skip method do in Cypress testing?
easy
A. It skips the marked test or group so it does not run.
B. It runs only the marked test or group and skips others.
C. It marks the test as failed automatically.
D. It retries the test multiple times before failing.

Solution

  1. Step 1: Understand the purpose of .skip

    The .skip method is used to tell Cypress to ignore a test or group during execution.
  2. Step 2: Compare with other methods

    Unlike .only, which runs only the marked tests, .skip prevents the marked tests from running.
  3. Final Answer:

    It skips the marked test or group so it does not run. -> Option A
  4. Quick Check:

    .skip = skip test [OK]
Hint: Remember: skip means ignore this test [OK]
Common Mistakes:
  • Confusing .skip with .only
  • Thinking .skip runs the test
  • Assuming .skip marks test as failed
2. Which of the following is the correct syntax to run only one test in Cypress?
easy
A. it.skip('test name', () => { /* test code */ })
B. describe.only('group name', () => { /* tests */ })
C. it.only('test name', () => { /* test code */ })
D. describe.skip('group name', () => { /* tests */ })

Solution

  1. Step 1: Identify the method to run only one test

    The it.only syntax runs only the marked test and skips all others.
  2. Step 2: Check other options

    it.skip skips a test, describe.only runs only a group, and describe.skip skips a group.
  3. Final Answer:

    it.only('test name', () => { /* test code */ }) -> Option C
  4. Quick Check:

    it.only runs only one test [OK]
Hint: Use it.only to run just one test [OK]
Common Mistakes:
  • Using describe.only to run a single test
  • Confusing skip and only syntax
  • Forgetting parentheses in function
3. Given the code below, which tests will run?
describe('Group A', () => {
  it('Test 1', () => { /* code */ })
  it.only('Test 2', () => { /* code */ })
  it('Test 3', () => { /* code */ })
})
describe.only('Group B', () => {
  it('Test 4', () => { /* code */ })
  it('Test 5', () => { /* code */ })
})
medium
A. All tests in both groups run.
B. All tests in Group A run except Test 2.
C. Only Test 2 runs, Group B tests are skipped.
D. Only all tests in Group B run.

Solution

  1. Step 1: Understand describe.only effect

    The describe.only('Group B') means only Group B runs; Group A is skipped.
  2. Step 2: Understand it.only inside Group A

    Even though it.only('Test 2') is inside Group A, Group A is skipped entirely because of describe.only on Group B.
  3. Step 3: Determine which tests run

    All tests inside Group B run (Test 4 and Test 5). Test 2 does not run because Group A is skipped.
  4. Final Answer:

    Only all tests in Group B run. -> Option D
  5. Quick Check:

    describe.only overrides it.only [OK]
Hint: describe.only runs only that group, ignoring it.only inside others [OK]
Common Mistakes:
  • Thinking it.only inside skipped describe runs
  • Ignoring describe.only effect
  • Assuming all tests run
4. You have this Cypress test code:
describe.skip('Group X', () => {
  it.only('Test A', () => { /* code */ })
  it('Test B', () => { /* code */ })
})
describe('Group Y', () => {
  it('Test C', () => { /* code */ })
})
What is the problem with this code?
medium
A. Test C will run but Group X tests will be skipped.
B. Test A will run but Test B and Test C will be skipped.
C. Test A will run but Group Y tests will be skipped.
D. No tests will run because the entire Group X is skipped.

Solution

  1. Step 1: Analyze describe.skip effect on Group X

    The entire Group X is skipped, so none of its tests run, including it.only.
  2. Step 2: Analyze Group Y tests

    Group Y is not skipped, so its test (Test C) runs normally.
  3. Final Answer:

    Test C will run but Group X tests will be skipped. -> Option A
  4. Quick Check:

    describe.skip skips whole group, ignoring it.only [OK]
Hint: describe.skip disables all tests inside, even it.only [OK]
Common Mistakes:
  • Assuming it.only overrides describe.skip
  • Thinking some tests in skipped group run
  • Confusing which group is skipped
5. You want to run only a specific test inside a group but also skip another test in the same group. Which is the correct way to do this?
describe('My Tests', () => {
  it('Test 1', () => { /* code */ })
  it('Test 2', () => { /* code */ })
  it('Test 3', () => { /* code */ })
})
Options: A) Add .only to Test 2 and .skip to Test 3. B) Add .skip to Test 1 and .only to Test 3. C) Add .only to Test 1 and .skip to Test 2. D) Add .skip to Test 2 and .skip to Test 3.
hard
A. Add .skip to Test 1 and .only to Test 3.
B. Add .only to Test 2 and .skip to Test 3.
C. Add .only to Test 1 and .skip to Test 2.
D. Add .skip to Test 2 and .skip to Test 3.

Solution

  1. Step 1: Understand .only and .skip usage

    Using .only on a test runs only that test, skipping all others unless they also have .only. Using .skip skips that test.
  2. Step 2: Apply to given tests

    To run only Test 2 and skip Test 3, add .only to Test 2 and .skip to Test 3. Test 1 will be skipped automatically because of .only.
  3. Final Answer:

    Add .only to Test 2 and .skip to Test 3. -> Option B
  4. Quick Check:

    .only runs test, .skip skips test [OK]
Hint: Use .only on test to run, .skip on test to ignore [OK]
Common Mistakes:
  • Adding .only to multiple tests without need
  • Skipping tests that .only already excludes
  • Confusing which test to skip or run
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard