Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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‎

Lines changed: 7 additions & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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‎

Lines changed: 23 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /