Testing v-for Directive Transformation in dcloudio/uni-app Xiaohongshu Platform
This test suite validates v-for directive transformation in the uni-app framework for the Red Book (Xiaohongshu) mini-program platform. It ensures proper conversion of Vue’s v-for syntax to Xiaohongshu’s native xhs:for template syntax.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-mp-xhs/__tests__/vFor.spec.ts
import { assert } from './testUtils'
describe(`mp-xhs: transform v-for`, () => {
test(`with key`, () => {
assert(
`<view v-for="item in items" :key="item.id"/>`,
`<view xhs:for="{{a}}" xhs:for-item="item" xhs:key="a"/>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: item.id }; }) }
}`
)
})
test(`without key`, () => {
assert(
`<view v-for="item in items"/>`,
`<view xhs:for="{{a}}" xhs:for-item="item"/>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
})