0
0
Cypresstesting~20 mins

cypress-testing-library - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cypress Testing Library Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the test result of this Cypress code snippet?
Consider this Cypress test using cypress-testing-library commands. What will be the test execution result?
Cypress
describe('Button click test', () => {
  it('should find and click the submit button', () => {
    cy.visit('/form')
    cy.findByRole('button', { name: /submit/i }).click()
    cy.findByText(/form submitted/i).should('exist')
  })
})
ATest passes but the assertion cy.findByText(/form submitted/i).should('exist') is incorrect syntax.
BTest fails because cy.findByRole does not exist in cypress-testing-library.
CTest passes because the button is found and the confirmation text appears.
DTest fails due to a syntax error in the test code.
Attempts:
2 left
💡 Hint
Remember that cypress-testing-library extends Cypress with findByRole and findByText commands.
assertion
intermediate
1:30remaining
Which assertion correctly verifies an input field is disabled using cypress-testing-library?
You want to check if an input field with label 'Email' is disabled. Which assertion is correct?
Acy.findByLabelText('Email').should('be.disabled')
Bcy.findByLabelText('Email').should('be.enabled')
Ccy.findByLabelText('Email').should('not.be.enabled')
Dcy.findByLabelText('Email').should('have.attr', 'disabled', false)
Attempts:
2 left
💡 Hint
Use the correct Cypress assertion for disabled elements.
locator
advanced
1:30remaining
Which locator best follows testing-library best practices to find a checkbox labeled 'Accept Terms'?
Choose the best locator to find the checkbox input associated with the label 'Accept Terms' using cypress-testing-library.
Acy.get('#acceptTermsCheckbox')
Bcy.get('input[type="checkbox"][name="accept"]')
Ccy.findByLabelText('Accept Terms')
Dcy.findByRole('checkbox', { name: 'Accept Terms' })
Attempts:
2 left
💡 Hint
Testing-library encourages queries by role with accessible name.
🔧 Debug
advanced
2:00remaining
Why does this cypress-testing-library test fail to find the button?
Given the code below, why does the test fail to find the button labeled 'Save'? cy.visit('/settings') cy.findByRole('button', { name: 'Save' }).click()
AThe button is inside an iframe, and cypress-testing-library cannot access elements inside iframes by default.
BThe button does not have a role attribute set to 'button', so findByRole fails.
CThe button text is 'save' lowercase, so the name option is case sensitive and fails.
DThe test is missing a cy.wait() before findByRole, so the button is not yet rendered.
Attempts:
2 left
💡 Hint
Consider DOM context and accessibility tree when using findByRole.
framework
expert
2:30remaining
Which cypress-testing-library command chain correctly waits for an async element to appear before asserting?
You want to wait for a loading spinner to disappear and then check that a 'Data Loaded' message appears. Which command chain is correct?
A
cy.findByTestId('spinner').should('not.exist')
cy.findByText('Data Loaded').should('exist')
Bcy.findByTestId('spinner').should('not.exist').then(() => cy.findByText('Data Loaded').should('exist'))
Ccy.findByTestId('spinner').should('not.exist').findByText('Data Loaded').should('exist')
Dcy.findByTestId('spinner').should('not.exist').wait(1000).findByText('Data Loaded').should('exist')
Attempts:
2 left
💡 Hint
Use chaining and then() to sequence assertions after async waits.