Testing v-for Directive Transformation in uni-app Baidu Mini Program
This test suite validates the transformation of v-for directives in the Baidu Mini Program context within uni-app. It ensures proper handling of list rendering with and without key attributes, verifying the correct compilation of Vue-style v-for syntax to Baidu’s s-for template syntax.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-mp-baidu/__tests__/vFor.spec.ts
import { assert } from './testUtils'
describe(`mp-baidu: transform v-for`, () => {
test(`with key`, () => {
assert(
`<view v-for="item in items" :key="item.id"/>`,
`<view s-for="item in a trackBy item.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 s-for="item in a"/>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return {}; }) }
}`
)
})
})