Skip to content

Commit 5036f91

Browse files
authored
test(compiler-vapor): add index test for v-for (#13004)
1 parent d8ae428 commit 5036f91

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ export function render(_ctx) {
115115
}"
116116
`;
117117

118+
exports[`compiler: v-for > object value, key and index 1`] = `
119+
"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue';
120+
const t0 = _template("<div> </div>", true)
121+
122+
export function render(_ctx) {
123+
const n0 = _createFor(() => (_ctx.list), (_for_item0, _for_key0, _for_index0) => {
124+
const n2 = t0()
125+
const x2 = _child(n2)
126+
_renderEffect(() => _setText(x2, _toDisplayString(_for_item0.value + _for_key0.value + _for_index0.value)))
127+
return n2
128+
}, (value, key, index) => (key))
129+
return n0
130+
}"
131+
`;
132+
118133
exports[`compiler: v-for > v-for aliases w/ complex expressions 1`] = `
119134
"import { getDefaultValue as _getDefaultValue, child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue';
120135
const t0 = _template("<div> </div>", true)

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,32 @@ describe('compiler: v-for', () => {
119119
})
120120
})
121121

122+
test('object value, key and index', () => {
123+
const { code, ir } = compileWithVFor(
124+
`<div v-for="(value, key, index) in list" :key="key">{{ value + key + index }}</div>`,
125+
)
126+
expect(code).matchSnapshot()
127+
expect(ir.block.operation[0]).toMatchObject({
128+
type: IRNodeTypes.FOR,
129+
source: {
130+
type: NodeTypes.SIMPLE_EXPRESSION,
131+
content: 'list',
132+
},
133+
value: {
134+
type: NodeTypes.SIMPLE_EXPRESSION,
135+
content: 'value',
136+
},
137+
key: {
138+
type: NodeTypes.SIMPLE_EXPRESSION,
139+
content: 'key',
140+
},
141+
index: {
142+
type: NodeTypes.SIMPLE_EXPRESSION,
143+
content: 'index',
144+
},
145+
})
146+
})
147+
122148
test('object de-structured value', () => {
123149
const { code, ir } = compileWithVFor(
124150
'<span v-for="({ id, value }) in items" :key="id">{{ id }}{{ value }}</span>',

0 commit comments

Comments
 (0)