Testing Swiper Component Attribute Transformation in uni-app
This test suite focuses on validating the swiper component transformation functionality in the uni-app framework’s Toutiao mini-program implementation. It specifically tests the disable-touch attribute binding and its conversion to the touchable property.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-mp-toutiao/__tests__/swiper.spec.ts
import { assert } from './testUtils'
describe('mp-toutiao: transform swiper', () => {
// test(`attribute disable-touch`, () => {
// assert(
// `<swiper disable-touch/>`,
// `<swiper touchable="{{false}}"/>`,
// `(_ctx, _cache) => {
// return {}
// }`
// )
// assert(
// `<swiper disable-touch="false"/>`,
// `<swiper touchable="{{false}}"/>`,
// `(_ctx, _cache) => {
// return {}
// }`
// )
// })
test(`v-bind disable-touch`, () => {
assert(
`<swiper :disable-touch="true"/>`,
`<swiper touchable="{{false}}"/>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<swiper :disable-touch="false"/>`,
`<swiper touchable="{{true}}"/>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<swiper :disable-touch="disableTouch"/>`,
`<swiper touchable="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: !_ctx.disableTouch }
}`
)
})
})