Challenge - 5 Problems
Cypress Skip & Only Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the test execution result?
Consider this Cypress test code snippet:
Which tests will run when this suite executes?
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') }) })
Attempts:
2 left
💡 Hint
Remember that .skip prevents that specific test from running.
✗ Incorrect
The .skip method tells Cypress to skip that particular test. So Test 2 is skipped, while Test 1 and Test 3 run normally.
❓ Predict Output
intermediate2:00remaining
Which tests run with .only?
Given this Cypress test suite:
Which tests will execute?
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') }) })
Attempts:
2 left
💡 Hint
Think about how .only focuses on a single test.
✗ Incorrect
The .only method tells Cypress to run only that test and skip all others in the suite.
❓ assertion
advanced2: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?
Which assertion correctly checks that the skipped test's log is NOT present in the Cypress command log?
Attempts:
2 left
💡 Hint
Skipped tests do not produce logs, so the log text should be absent.
✗ Incorrect
Since the skipped test does not run, its log message should not appear. The assertion checks that the log does NOT contain that message.
❓ framework
advanced2:00remaining
What happens if multiple tests use .only in Cypress?
In a Cypress test file, two tests are marked with .only:
What will Cypress do when running this file?
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') })
Attempts:
2 left
💡 Hint
Check how Cypress handles multiple .only tests.
✗ Incorrect
Cypress runs all tests marked with .only and skips all others. Multiple .only tests run together.
🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
Think about how .only changes which tests run.
✗ Incorrect
Using .only runs only the focused tests and skips the rest. If committed, this can hide failures in skipped tests and give false confidence.