Testing v-text Directive Transformation in uni-app Compiler
This test suite evaluates the v-text directive transformation functionality in the uni-app compiler for mini-program platforms. It verifies proper text binding and interpolation across different syntax variations and element structures.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-mp-compiler/__tests__/vText.spec.ts
import { assert } from './testUtils'
describe('compiler: transform v-text', () => {
test('basic', () => {
assert(
`<view>{{text}}</view>`,
`<view>{{a}}</view>`,
`(_ctx, _cache) => {
return { a: _t(_ctx.text) }
}`
)
assert(
`<view v-text="text"></view>`,
`<view>{{a}}</view>`,
`(_ctx, _cache) => {
return { a: _t(_ctx.text) }
}`
)
assert(
`<view v-text="'text'"></view>`,
`<view>{{a}}</view>`,
`(_ctx, _cache) => {
return { a: _t('text') }
}`
)
})
test('self closing', () => {
assert(
`<view v-text="text"/>`,
`<view>{{a}}</view>`,
`(_ctx, _cache) => {
return { a: _t(_ctx.text) }
}`
)
})
})