Bird
Raised Fist0
Cypresstesting~20 mins

it blocks for test cases in Cypress - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Cypress it Block Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of nested it blocks in Cypress

Consider this Cypress test code snippet:

describe('My Test Suite', () => {
  it('Test case 1', () => {
    cy.visit('https://example.com')
  })

  it('Test case 2', () => {
    it('Nested test case', () => {
      cy.get('h1').should('be.visible')
    })
  })
})

What will happen when you run this test suite?

Cypress
describe('My Test Suite', () => {
  it('Test case 1', () => {
    cy.visit('https://example.com')
  })

  it('Test case 2', () => {
    it('Nested test case', () => {
      cy.get('h1').should('be.visible')
    })
  })
})
AOnly 'Test case 1' will run; the others will be ignored silently.
BBoth 'Test case 2' and 'Nested test case' will run sequentially without errors.
C'Nested test case' will run but 'Test case 2' will be skipped.
DThe test runner will throw an error because nesting it blocks is not allowed.
Attempts:
2 left
💡 Hint

Think about how Cypress structures test cases and the role of it blocks.

❓ assertion
intermediate
2:00remaining
Correct assertion placement in it blocks

Which of the following is the correct way to write an assertion inside an it block in Cypress?

Ait('checks title', () => { cy.title().should('eq', 'My Page') })
Bit('checks title', () => { cy.title().then(title => { expect(title).to.eq('My Page') }) })
Cit('checks title', () => { expect(cy.title()).to.eq('My Page') })
Dit('checks title', () => { cy.title().should('equal', 'My Page') })
Attempts:
2 left
💡 Hint

Remember how Cypress commands and assertions work asynchronously.

🔧 Debug
advanced
2:00remaining
Debugging skipped tests inside it blocks

You have this Cypress test suite:

describe('Suite', () => {
  it.skip('skipped test', () => {
    cy.visit('https://example.com')
  })

  it('normal test', () => {
    cy.visit('https://example.com')
  })
})

What will be the result when running this suite?

Cypress
describe('Suite', () => {
  it.skip('skipped test', () => {
    cy.visit('https://example.com')
  })

  it('normal test', () => {
    cy.visit('https://example.com')
  })
})
ANeither test runs because one test is skipped.
BBoth tests run normally without skipping.
COnly 'normal test' runs; 'skipped test' is ignored and marked as skipped in the report.
DThe test runner throws an error because of the skip keyword.
Attempts:
2 left
💡 Hint

Think about the purpose of it.skip in Cypress.

🧠 Conceptual
advanced
2:00remaining
Purpose of it blocks in Cypress

What is the main purpose of an it block in Cypress testing?

ATo group multiple test suites together.
BTo define a single test case that Cypress will execute.
CTo set up preconditions before running tests.
DTo clean up after all tests have run.
Attempts:
2 left
💡 Hint

Think about what you want Cypress to do step-by-step.

❓ framework
expert
3:00remaining
Handling asynchronous commands inside it blocks

Consider this Cypress test:

it('checks element text', () => {
  let textContent = ''
  cy.get('#my-element').then(el => {
    textContent = el.text()
  })
  expect(textContent).to.equal('Hello')
})

What will be the result of this test?

Cypress
it('checks element text', () => {
  let textContent = ''
  cy.get('#my-element').then(el => {
    textContent = el.text()
  })
  expect(textContent).to.equal('Hello')
})
AThe test will fail because the expect runs before the textContent is set.
BThe test will pass because textContent is set correctly before the assertion.
CThe test will throw a syntax error due to incorrect use of then.
DThe test will be skipped because of asynchronous commands.
Attempts:
2 left
💡 Hint

Remember how Cypress commands run asynchronously and how JavaScript handles promises.

Practice

(1/5)
1. What is the main purpose of an it block in Cypress testing?
easy
A. To define reusable functions for tests
B. To group multiple test suites together
C. To hold and describe a single test case with its steps
D. To configure the Cypress environment settings

Solution

  1. Step 1: Understand the role of it blocks

    it blocks are used to write individual test cases in Cypress.
  2. Step 2: Differentiate from other blocks

    Unlike describe which groups tests, it holds one test with steps and description.
  3. Final Answer:

    To hold and describe a single test case with its steps -> Option C
  4. Quick Check:

    it block = single test case [OK]
Hint: Remember: it means 'this test' [OK]
Common Mistakes:
  • Confusing it with describe
  • Thinking it configures environment
  • Using it to group multiple tests
2. Which of the following is the correct syntax to write an it block in Cypress?
easy
A. it('checks title') => cy.title().should('include', 'Home')
B. it 'checks title' { cy.title().should('include', 'Home') }
C. it: 'checks title' => { cy.title().should('include', 'Home') }
D. it('checks title', () => { cy.title().should('include', 'Home') })

Solution

  1. Step 1: Check the function call syntax

    The it block requires a string description and a callback function wrapped in parentheses.
  2. Step 2: Validate arrow function and braces

    it('checks title', () => { cy.title().should('include', 'Home') }) correctly uses arrow function with braces and parentheses.
  3. Final Answer:

    it('checks title', () => { cy.title().should('include', 'Home') }) -> Option D
  4. Quick Check:

    Correct it syntax uses parentheses and arrow function [OK]
Hint: Use parentheses and arrow function for it [OK]
Common Mistakes:
  • Omitting parentheses around parameters
  • Using colon or wrong arrow syntax
  • Missing braces for function body
3. What will be the result of running this Cypress test?
it('checks page title', () => { cy.visit('https://example.com'); cy.title().should('eq', 'Example Domain'); });
medium
A. Test fails because cy.visit is missing a callback
B. Test passes if the page title is exactly 'Example Domain'
C. Test throws a syntax error due to missing semicolon
D. Test passes regardless of the page title

Solution

  1. Step 1: Analyze the test steps

    The test visits 'https://example.com' and checks if the page title equals 'Example Domain'.
  2. Step 2: Understand assertion behavior

    The assertion should('eq', 'Example Domain') passes only if the title matches exactly.
  3. Final Answer:

    Test passes if the page title is exactly 'Example Domain' -> Option B
  4. Quick Check:

    Correct assertion = test passes if title matches [OK]
Hint: Check exact match with should('eq', ...) [OK]
Common Mistakes:
  • Assuming cy.visit needs a callback
  • Ignoring assertion conditions
  • Confusing semicolons with syntax errors
4. Identify the error in this it block:
it('checks button', () => { cy.get('#submit').click() cy.get('#message').should('be.visible') })
medium
A. No error; the test will run correctly
B. Missing semicolon after click() causes syntax error
C. The it block is missing a description string
D. The selector #submit is invalid

Solution

  1. Step 1: Check syntax for semicolons

    JavaScript allows optional semicolons; missing one here does not cause error.
  2. Step 2: Verify test structure and selectors

    The it block has a description and valid selectors; no syntax or logic errors.
  3. Final Answer:

    No error; the test will run correctly -> Option A
  4. Quick Check:

    Missing semicolons often allowed; test runs fine [OK]
Hint: Semicolons optional in JS; focus on logic errors [OK]
Common Mistakes:
  • Assuming missing semicolon always causes error
  • Confusing missing description with error
  • Thinking selectors are invalid without context
5. You want to write two it blocks to test login and logout separately. Which is the best practice?
hard
A. Write two it blocks inside one describe block, each with clear descriptions
B. Write both tests inside a single it block to save time
C. Write it blocks without descriptions to keep code short
D. Use multiple describe blocks but only one it block

Solution

  1. Step 1: Understand test organization

    Each it block should hold one test case with a clear description.
  2. Step 2: Group related tests

    Using one describe block to group login and logout tests keeps tests organized and readable.
  3. Final Answer:

    Write two it blocks inside one describe block, each with clear descriptions -> Option A
  4. Quick Check:

    Separate tests in it blocks grouped by describe [OK]
Hint: Group tests with describe, separate with it [OK]
Common Mistakes:
  • Combining multiple tests in one it block
  • Skipping descriptions for it blocks
  • Using multiple describe blocks unnecessarily
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