Skip to content

Commit ed6041d

Browse files
tran2eddyerburgh
authored andcommitted
fix: add _compiled to functional so that it handles slot properly (#90)
1 parent 7c2f268 commit ed6041d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/process.js

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ module.exports = function (src, filePath, jestConfig) {
6969

7070
if (parts.template.attrs.functional) {
7171
output += '__vue__options__.functional = true\n'
72+
output += '__vue__options__._compiled = true\n'
7273
}
7374

7475
if (map) {

test/FunctionalSFC.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@ describe('Processes .vue file with functional template', () => {
2525
// note: for new version of @vue/vue-utils we can use wrapper.isFunctionalComponent for this
2626
expect(wrapper.vm._vnode.fnOptions.functional).toBe(true)
2727
})
28+
29+
it('handles slot', () => {
30+
wrapper = shallow(FunctionalSFC, {
31+
context: {
32+
props: { msg: { id: 1, title: '' }},
33+
children: ['this is a slot']
34+
}
35+
})
36+
37+
expect(wrapper.text()).toBe('this is a slot')
38+
})
2839
})

test/resources/FunctionalSFC.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<template functional>
2-
<button @click="props.onClick(props.msg.id)">{{props.msg.title}}</button>
2+
<div @click="props.onClick(props.msg.id)">
3+
{{props.msg.title}}
4+
<slot></slot>
5+
</div>
36
</template>

0 commit comments

Comments
 (0)