Skip to content

Commit 43d8680

Browse files
committed
test(vIf): add test for v-on with v-if handling
1 parent 174656a commit 43d8680

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,17 @@ export function render(_ctx) {
308308
return n0
309309
}"
310310
`;
311+
312+
exports[`compiler: v-if > v-on with v-if 1`] = `
313+
"import { setDynamicEvents as _setDynamicEvents, renderEffect as _renderEffect, createIf as _createIf, template as _template } from 'vue';
314+
const t0 = _template("<button>w/ v-if</button>", true)
315+
316+
export function render(_ctx) {
317+
const n0 = _createIf(() => (true), () => {
318+
const n2 = t0()
319+
_renderEffect(() => _setDynamicEvents(n2, { click: _ctx.clickEvent }))
320+
return n2
321+
}, null, true)
322+
return n0
323+
}"
324+
`;

packages/compiler-vapor/__tests__/transforms/vIf.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,30 @@ describe('compiler: v-if', () => {
380380
])
381381
})
382382

383+
test('v-on with v-if', () => {
384+
const { code, ir } = compileWithVIf(
385+
`<button v-on="{ click: clickEvent }" v-if="true">w/ v-if</button>`,
386+
)
387+
expect(code).toMatchSnapshot()
388+
expect([...ir.template.keys()]).toEqual(['<button>w/ v-if</button>'])
389+
390+
expect(ir.block.returns).toEqual([0])
391+
expect(ir.block.dynamic.children[0].operation).toMatchObject({
392+
type: IRNodeTypes.IF,
393+
condition: {
394+
type: NodeTypes.SIMPLE_EXPRESSION,
395+
content: 'true',
396+
isStatic: false,
397+
},
398+
positive: {
399+
type: IRNodeTypes.BLOCK,
400+
dynamic: {
401+
children: [{ template: 0 }],
402+
},
403+
},
404+
})
405+
})
406+
383407
describe('errors', () => {
384408
test('error on v-else missing adjacent v-if', () => {
385409
const onError = vi.fn()

0 commit comments

Comments
 (0)