Skip to content

Commit ab0f94e

Browse files
committed
Simplify the slots example
1 parent bbabed2 commit ab0f94e

File tree

2 files changed

+15
-48
lines changed

2 files changed

+15
-48
lines changed

src/__tests__/components/Card.vue

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
<template>
22
<div class="card">
33
<slot name="header" />
4-
<slot :content="content">
5-
<!-- Fallback content if no default slot is given -->
6-
<p>Nothing used the {{ content }}</p>
7-
</slot>
84
<slot name="footer" />
95
</div>
106
</template>
11-
12-
<script>
13-
// For the sake of demoing scopedSlots, this Card component
14-
// passes a simple string down to its default slot.
15-
export default {
16-
data() {
17-
return {
18-
content: 'Scoped content!'
19-
}
20-
}
21-
}
22-
</script>

src/__tests__/slots.js

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,17 @@
1-
test.todo('Your test suite must contain at least one test.')
1+
import '@testing-library/jest-dom'
2+
import {render} from '@testing-library/vue'
3+
import Card from './components/Card'
24

3-
// import '@testing-library/jest-dom'
4-
// import {render} from '@testing-library/vue'
5-
// import Card from './components/Card'
5+
// Usage is the same as Vue Test Utils, since slots values are passed using the `slots`
6+
// key from mount(). For more, see: https://vue-test-utils.vuejs.org/api/options.html#slots
7+
test('Card component', () => {
8+
const {getByText} = render(Card, {
9+
slots: {
10+
header: '<h1>HEADER</h1>',
11+
footer: '<div>FOOTER</div>',
12+
},
13+
})
614

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

0 commit comments

Comments
 (0)