Skip to content

Commit 9b2a6ff

Browse files
authored
test: v-once as root node (#2)
1 parent bdbd524 commit 9b2a6ff

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap

+15-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,21 @@ export function render() {
7575
"
7676
`;
7777

78-
exports[`comile > directives > v-once 1`] = `
78+
exports[`comile > directives > v-once > as root node 1`] = `
79+
"import { watchEffect } from 'vue';
80+
import { template, setAttr } from 'vue/vapor';
81+
const t0 = template(\`<div></div>\`);
82+
export function render() {
83+
const n0 = t0();
84+
watchEffect(() => {
85+
setAttr(n0, 'id', undefined, foo);
86+
});
87+
return n0;
88+
}
89+
"
90+
`;
91+
92+
exports[`comile > directives > v-once > basic 1`] = `
7993
"import { template, children, insert, setText, setAttr } from 'vue/vapor';
8094
const t0 = template(\`<div> <span></span></div>\`);
8195
export function render() {

packages/compiler-vapor/__tests__/compile.test.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,28 @@ describe('comile', () => {
9292
})
9393
})
9494

95-
test('v-once', async () => {
96-
const code = await compile(
97-
`<div v-once>
95+
describe('v-once', () => {
96+
test('basic', async () => {
97+
const code = await compile(
98+
`<div v-once>
9899
{{ msg }}
99100
<span :class="clz" />
100101
</div>`,
101-
{
102-
bindingMetadata: {
103-
msg: BindingTypes.SETUP_REF,
104-
clz: BindingTypes.SETUP_REF,
102+
{
103+
bindingMetadata: {
104+
msg: BindingTypes.SETUP_REF,
105+
clz: BindingTypes.SETUP_REF,
106+
},
105107
},
106-
},
107-
)
108-
expect(code).matchSnapshot()
108+
)
109+
expect(code).matchSnapshot()
110+
})
111+
112+
test.fails('as root node', async () => {
113+
const code = await compile(`<div :id="foo" v-once />`)
114+
expect(code).toMatchSnapshot()
115+
expect(code).not.contains('watchEffect')
116+
})
109117
})
110118
})
111119
})

0 commit comments

Comments
 (0)