Testing Scoped Slot Data Initialization in dcloudio/uni-app
This test suite examines the scoped slot data initialization functionality in the uni-mp-vue package. It verifies the correct handling of nested data paths and array indexing when initializing scoped slot data structures.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
dcloudio/uni-app
packages/uni-mp-vue/__tests__/withScopedSlot.spec.ts
import { initScopedSlotDataByPath } from '../src/helpers/withScopedSlot'
const tests: Record<string, Data> = {
a: {
a: [{ a: 1 }],
},
'a.b': {
a: {
b: [{ a: 1 }],
},
},
'a.0.b': {
a: [
{
b: [{ a: 1 }],
},
],
},
'a.1.b': {
a: createArrayData(1, { b: [{ a: 1 }] }),
},
'a.1.b.2.c.b': {
a: createArrayData(1, { b: createArrayData(2, { c: { b: [{ a: 1 }] } }) }),
},
}
function createArrayData(index: number, data: Data) {
const arr: Data[] = []
arr[index] = data
return arr
}
describe('uni-mp-vue: withScopedSlot', () => {
Object.keys(tests).forEach((path) => {
test(path, () => {
const data = {}
initScopedSlotDataByPath(path, { a: 1 }, data)
expect(data).toMatchObject(tests[path])
})
})
})