0
0
Cypresstesting~10 mins

Slot testing in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if a web page correctly displays content passed into a named slot in a web component. It verifies that the slot content is rendered and visible to the user.

Test Code - Cypress
Cypress
describe('Slot testing', () => {
  it('should display content inside the named slot', () => {
    cy.visit('/slot-test-page')
    cy.get('my-component').shadow().find('slot[name="header"]').then(slot => {
      cy.wrap(slot).invoke('prop', 'assignedNodes').should('have.length.greaterThan', 0)
    })
    cy.get('my-component').contains('Header Content').should('be.visible')
  })
})
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, no browser opened yet-PASS
2Browser opens and navigates to '/slot-test-page'Page with <my-component> loaded, slot elements present in shadow DOM-PASS
3Find the named slot 'header' inside the shadow DOM of <my-component>Slot element located inside shadow rootCheck that slot has assigned nodes (content passed into slot)PASS
4Verify that the content 'Header Content' is visible on the pageContent inside slot is rendered and visibleAssert that 'Header Content' text is visiblePASS
Failure Scenario
Failing Condition: The named slot 'header' has no assigned content or the content is not visible
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about the named slot 'header'?
AThat the slot has content assigned and it is visible
BThat the slot is empty
CThat the slot is hidden
DThat the slot is disabled
Key Result
Always verify that content passed into slots is actually rendered and visible, especially when testing web components with shadow DOM.