|
| 1 | +import '@testing-library/jest-dom/extend-expect' |
| 2 | +import { render } from '@testing-library/vue' |
| 3 | +import Card from './components/Card' |
| 4 | + |
| 5 | +// In this test file we demo how to test a component with slots and a scoped slot. |
| 6 | + |
| 7 | +// Usage is the same as Vue Test Utils, since slots and scopedSlots |
| 8 | +// in the render options are directly passed through to the Utils mount(). |
| 9 | +// For more, see: https://vue-test-utils.vuejs.org/api/options.html#slots |
| 10 | +test('Card component', () => { |
| 11 | + const { getByText, queryByText } = render(Card, { |
| 12 | + slots: { |
| 13 | + header: '<h1>HEADER</h1>', |
| 14 | + footer: '<div>FOOTER</div>' |
| 15 | + }, |
| 16 | + scopedSlots: { |
| 17 | + default: '<p>Yay! {{props.content}}</p>' |
| 18 | + } |
| 19 | + }) |
| 20 | + |
| 21 | + // The default slot should render the template above with the scoped prop "content". |
| 22 | + getByText('Yay! Scoped content!') |
| 23 | + |
| 24 | + // Instead of the default slot's fallback content. |
| 25 | + expect( |
| 26 | + queryByText('Nothing used the Scoped content!') |
| 27 | + ).not.toBeInTheDocument() |
| 28 | + |
| 29 | + // And the header and footer slots should be rendered with the given templates. |
| 30 | + getByText('HEADER') |
| 31 | + getByText('FOOTER') |
| 32 | +}) |
0 commit comments