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.
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.
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') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser opened yet | — | PASS |
| 2 | Browser opens and navigates to '/slot-test-page' | Page with <my-component> loaded, slot elements present in shadow DOM | — | PASS |
| 3 | Find the named slot 'header' inside the shadow DOM of <my-component> | Slot element located inside shadow root | Check that slot has assigned nodes (content passed into slot) | PASS |
| 4 | Verify that the content 'Header Content' is visible on the page | Content inside slot is rendered and visible | Assert that 'Header Content' text is visible | PASS |
slot tag with a name attribute, so selector is slot[name="header"].cy.get('slot[name="header"]') correctly targets the named slot.cy.get('slot[name="footer"]').should('contain.text', 'Contact us')should('contain.text', 'Contact us') checks if the slot text includes the substring 'Contact us'.cy.get('slot[name="main"]').should('have.text', 'Welcome')slot:not([name]).slot[name="sidebar"].contain.text to check fallback 'No content' and sidebar 'Menu'.Pass the test and this pattern moves unknown