Skip to content

Commit b430986

Browse files
committed
Add functional rendering support and examples
1 parent 8b51a04 commit b430986

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/vue-testing-library.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,19 @@ function cleanup() {
8181
}
8282

8383
function cleanupAtWrapper(wrapper) {
84+
console.dir(wrapper)
85+
8486
if (
8587
wrapper.element.parentNode &&
8688
wrapper.element.parentNode.parentNode === document.body
8789
) {
8890
document.body.removeChild(wrapper.element.parentNode)
8991
}
90-
wrapper.destroy()
92+
93+
if (wrapper.isVueInstance()) {
94+
wrapper.destroy()
95+
}
96+
9197
mountedWrappers.delete(wrapper)
9298
}
9399

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template functional>
2+
<p>Hi!</p>
3+
</template>

tests/__tests__/functional.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { cleanup, render } from '@testing-library/vue'
2+
import FunctionalSFC from './components/FunctionalSFC'
3+
4+
const Functional = {
5+
functional: true,
6+
render(createElement) {
7+
return createElement('p', null, 'Hi!')
8+
}
9+
}
10+
11+
afterEach(cleanup)
12+
13+
it('renders functional comp', () => {
14+
const { getByText } = render(Functional)
15+
16+
getByText('Hi!')
17+
})
18+
19+
it('renders functional SFC comp', () => {
20+
const { getByText } = render(FunctionalSFC)
21+
22+
getByText('Hi!')
23+
})

0 commit comments

Comments
 (0)