Skip to content

Commit 256ef36

Browse files
committed
test(v-once): add test for v-once in slot outlet
1 parent ad9da61 commit 256ef36

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/runtime-vapor/__tests__/componentSlots.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
renderEffect,
1515
setInsertionState,
1616
template,
17+
txt,
1718
vaporInteropPlugin,
1819
withVaporCtx,
1920
} from '../src'
@@ -774,6 +775,42 @@ describe('component: slots', () => {
774775
await nextTick()
775776
expect(html()).toBe('<span>2</span><!--for--><!--slot-->')
776777
})
778+
779+
test('work with v-once', async () => {
780+
const Child = defineVaporComponent({
781+
setup() {
782+
return createSlot(
783+
'default',
784+
null,
785+
undefined,
786+
undefined,
787+
true /* once */,
788+
)
789+
},
790+
})
791+
792+
const count = ref(0)
793+
794+
const { html } = define({
795+
setup() {
796+
return createComponent(Child, null, {
797+
default: withVaporCtx(() => {
798+
const n3 = template('<div> </div>')() as any
799+
const x3 = txt(n3) as any
800+
renderEffect(() => setText(x3, toDisplayString(count.value)))
801+
return n3
802+
}),
803+
})
804+
},
805+
}).render()
806+
807+
expect(html()).toBe('<div>0</div><!--slot-->')
808+
809+
// expect no changes due to v-once
810+
count.value++
811+
await nextTick()
812+
expect(html()).toBe('<div>0</div><!--slot-->')
813+
})
777814
})
778815

779816
describe('forwarded slot', () => {

0 commit comments

Comments
 (0)