Bird
0
0

Given the code below, which tests will run?

medium📝 Predict Output Q13 of 15
Cypress - Writing Tests
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 */ })
})
AAll tests in both groups run.
BAll tests in Group A run except Test 2.
COnly Test 2 runs, Group B tests are skipped.
DOnly all tests in Group B run.
Step-by-Step Solution
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]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes