提交 4d404eb0 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(composition api): 调整示例及测试兼容 web

上级 672d9b42
<template> <template>
<view> <view>
<text class="bold">array literal</text> <text class="bold">array literal</text>
<button id="array-literal-emit-btn" class="uni-common-mt" @click="emitChange">emit change</button> <button class="array-literal-emit-btn uni-common-mt" @click="emitChange">emit change</button>
</view> </view>
</template> </template>
......
const PAGE_PATH = '/pages/composition-api/basic/define-emits/define-emits' const PAGE_PATH = '/pages/composition-api/basic/define-emits/define-emits'
describe('defineEmits', () => { describe('defineEmits', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const handleArrayLiteralChangeRes = await page.$('#handle-array-literal-change-res')
const handleArrayLiteralChangeRes = await page.$('#handle-array-literal-change-res') expect((await handleArrayLiteralChangeRes.text()).trim()).toBe('handle array literal comp change result:')
expect(await handleArrayLiteralChangeRes.text()).toBe('handle array literal comp change result: ')
const arrayLiteralEmitBtn = await page.$('.array-literal-emit-btn')
const arrayLiteralEmitBtn = await page.$('#array-literal-emit-btn') await arrayLiteralEmitBtn.tap()
await arrayLiteralEmitBtn.tap()
expect(await handleArrayLiteralChangeRes.text()).toBe(
expect(await handleArrayLiteralChangeRes.text()).toBe('handle array literal comp change result: options is 1') 'handle array literal comp change result: options is 1')
const handleTypeEmits1ChangeRes = await page.$('#handle-type-emits1-change-res') const handleTypeEmits1ChangeRes = await page.$('#handle-type-emits1-change-res')
expect(await handleTypeEmits1ChangeRes.text()).toBe('handle type emits comp change result: ') expect((await handleTypeEmits1ChangeRes.text()).trim()).toBe('handle type emits comp change result:')
const typeEmits1EmitBtn = await page.$('#type-emits1-emit-btn') const typeEmits1EmitBtn = await page.$('.type-emits1-emit-btn')
await typeEmits1EmitBtn.tap() await typeEmits1EmitBtn.tap()
expect(await handleTypeEmits1ChangeRes.text()).toBe('handle type emits comp change result: options is 2') expect(await handleTypeEmits1ChangeRes.text()).toBe('handle type emits comp change result: options is 2')
const handleTypeEmits2ChangeRes = await page.$('#handle-type-emits2-change-res') const handleTypeEmits2ChangeRes = await page.$('#handle-type-emits2-change-res')
expect(await handleTypeEmits2ChangeRes.text()).toBe('handle type emits named tuple syntax comp change result: ') expect((await handleTypeEmits2ChangeRes.text()).trim()).toBe(
'handle type emits named tuple syntax comp change result:')
const typeEmits2EmitBtn = await page.$('#type-emits2-emit-btn')
await typeEmits2EmitBtn.tap() const typeEmits2EmitBtn = await page.$('.type-emits2-emit-btn')
await typeEmits2EmitBtn.tap()
expect(await handleTypeEmits2ChangeRes.text()).toBe('handle type emits named tuple syntax comp change result: options is 3')
}) expect(await handleTypeEmits2ChangeRes.text()).toBe(
} else { 'handle type emits named tuple syntax comp change result: options is 3')
it('other platform', () => { })
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
<template> <template>
<view> <view>
<text class="uni-common-mt bold">type emits</text> <text class="uni-common-mt bold">type emits</text>
<button id="type-emits1-emit-btn" class="uni-common-mt" @click="emitChange">emit change</button> <button class="type-emits1-emit-btn uni-common-mt" @click="emitChange">emit change</button>
</view> </view>
</template> </template>
......
<template> <template>
<view> <view>
<text class="uni-common-mt bold">type emits named tuple syntax</text> <text class="uni-common-mt bold">type emits named tuple syntax</text>
<button id="type-emits2-emit-btn" class="uni-common-mt" @click="emitChange">emit change</button> <button class="type-emits2-emit-btn uni-common-mt" @click="emitChange">emit change</button>
</view> </view>
</template> </template>
......
const PAGE_PATH = '/pages/composition-api/basic/define-options/define-options' const PAGE_PATH = '/pages/composition-api/basic/define-options/define-options'
describe('defineOptions', () => { describe('defineOptions', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const count = await page.$('#count')
const count = await page.$('#count') expect(await count.text()).toBe('count: 0')
expect(await count.text()).toBe('count: 0') const doubleCount = await page.$('#double-count')
const doubleCount = await page.$('#double-count') expect(await doubleCount.text()).toBe('double count: 0')
expect(await doubleCount.text()).toBe('double count: 0') const total = await page.$('#total')
const total = await page.$('#total') expect(await total.text()).toBe('total: 0')
expect(await total.text()).toBe('total: 0')
const incrementBtn = await page.$('.increment-btn')
const incrementBtn = await page.$('#increment-btn') await incrementBtn.tap()
await incrementBtn.tap()
expect(await count.text()).toBe('count: 1')
expect(await count.text()).toBe('count: 1') expect(await doubleCount.text()).toBe('double count: 2')
expect(await doubleCount.text()).toBe('double count: 2') const price = await page.data('price')
const price = await page.data('price') expect(await total.text()).toBe(`total: ${1*price}`)
expect(await total.text()).toBe(`total: ${1*price}`) })
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<text id="count" class='uni-common-mb'>count: {{ count }}</text> <text id="count" class='uni-common-mb'>count: {{ count }}</text>
<text id='double-count' class='uni-common-mb'>double count: {{ doubleCount}}</text> <text id='double-count' class='uni-common-mb'>double count: {{ doubleCount}}</text>
<text id="total" class='uni-common-mb'>total: {{ total}}</text> <text id="total" class='uni-common-mb'>total: {{ total}}</text>
<button id="increment-btn" @click="increment">increment</button> <button class="increment-btn" @click="increment">increment</button>
</view> </view>
</template> </template>
......
const PAGE_PATH = '/pages/composition-api/basic/define-props/define-props' const PAGE_PATH = '/pages/composition-api/basic/define-props/define-props'
describe('defineProps', () => { describe('defineProps', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const arrayLiteralStr = await page.$('#array-literal-str')
const arrayLiteralStr = await page.$('#array-literal-str') expect(await arrayLiteralStr.text()).toBe('str: default str')
expect(await arrayLiteralStr.text()).toBe('str: default str') const arrayLiteralNum = await page.$('#array-literal-num')
const arrayLiteralNum = await page.$('#array-literal-num') expect(await arrayLiteralNum.text()).toBe('num: 0')
expect(await arrayLiteralNum.text()).toBe('num: 0') const arrayLiteralBool = await page.$('#array-literal-bool')
const arrayLiteralBool = await page.$('#array-literal-bool') expect(await arrayLiteralBool.text()).toBe('bool: false')
expect(await arrayLiteralBool.text()).toBe('bool: false') const arrayLiteralArr = await page.$('#array-literal-arr')
const arrayLiteralArr = await page.$('#array-literal-arr') expect((await arrayLiteralArr.text()).replaceAll('\n', '')).toBe('arr: ["a","b","c"]')
expect(await arrayLiteralArr.text()).toBe('arr: ["a","b","c"]')
const arrayLiteralObj = await page.$('#array-literal-obj') const arrayLiteralObj = await page.$('#array-literal-obj')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await arrayLiteralObj.text()).toBe('obj: {"arr":[1,2,3],"num":0,"str":"obj str"}') expect(await arrayLiteralObj.text()).toBe('obj: {"arr":[1,2,3],"num":0,"str":"obj str"}')
const arrayLiteralFn = await page.$('#array-literal-fn') }
expect(await arrayLiteralFn.text()).toBe('fn: fn res') if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect((await arrayLiteralObj.text()).replaceAll('\n', '')).toBe(
'obj: {"str": "obj str","num": 0,"arr": [1,2,3]}')
}
const objectLiteralStr = await page.$('#object-literal-str') const arrayLiteralFn = await page.$('#array-literal-fn')
expect(await objectLiteralStr.text()).toBe('str: default str') expect(await arrayLiteralFn.text()).toBe('fn: fn res')
const objectLiteralNum = await page.$('#object-literal-num')
expect(await objectLiteralNum.text()).toBe('num: 0') const objectLiteralStr = await page.$('#object-literal-str')
const objectLiteralBool = await page.$('#object-literal-bool') expect(await objectLiteralStr.text()).toBe('str: default str')
expect(await objectLiteralBool.text()).toBe('bool: false') const objectLiteralNum = await page.$('#object-literal-num')
const objectLiteralArr = await page.$('#object-literal-arr') expect(await objectLiteralNum.text()).toBe('num: 0')
expect(await objectLiteralArr.text()).toBe('arr: ["a","b","c"]') const objectLiteralBool = await page.$('#object-literal-bool')
const objectLiteralObj = await page.$('#object-literal-obj') expect(await objectLiteralBool.text()).toBe('bool: false')
const objectLiteralArr = await page.$('#object-literal-arr')
expect((await objectLiteralArr.text()).replaceAll('\n', '')).toBe('arr: ["a","b","c"]')
const objectLiteralObj = await page.$('#object-literal-obj')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await objectLiteralObj.text()).toBe('obj: {"a":1}') expect(await objectLiteralObj.text()).toBe('obj: {"a":1}')
const objectLiteralFn = await page.$('#object-literal-fn') }
expect(await objectLiteralFn.text()).toBe('fn: fn res') if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect((await objectLiteralObj.text()).replaceAll('\n', '')).toBe('obj: {"a": 1}')
}
const objectLiteralFn = await page.$('#object-literal-fn')
expect(await objectLiteralFn.text()).toBe('fn: fn res')
const typeStr = await page.$('#type-str') const typeStr = await page.$('#type-str')
expect(await typeStr.text()).toBe('str: default str') expect(await typeStr.text()).toBe('str: default str')
const typeNum = await page.$('#type-num') const typeNum = await page.$('#type-num')
expect(await typeNum.text()).toBe('num: 0') expect(await typeNum.text()).toBe('num: 0')
const typeBool = await page.$('#type-bool') const typeBool = await page.$('#type-bool')
expect(await typeBool.text()).toBe('bool: false') expect(await typeBool.text()).toBe('bool: false')
const typeArr = await page.$('#type-arr') const typeArr = await page.$('#type-arr')
expect(await typeArr.text()).toBe('arr: ["a","b","c"]') expect((await typeArr.text()).replaceAll('\n', '')).toBe('arr: ["a","b","c"]')
const typeObj = await page.$('#type-obj')
const typeObj = await page.$('#type-obj')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await typeObj.text()).toBe('obj: {"arr":[1,2,3],"num":0,"str":"obj str"}') expect(await typeObj.text()).toBe('obj: {"arr":[1,2,3],"num":0,"str":"obj str"}')
const typeFn = await page.$('#type-fn') }
expect(await typeFn.text()).toBe('fn: fn res') if (process.env.uniTestPlatformInfo.startsWith('web')) {
}) expect((await typeObj.text()).replaceAll('\n', '')).toBe('obj: {"str": "obj str","num": 0,"arr": [1,2,3]}')
} else {
it('other platform', () => { }
expect(1).toBe(1) const typeFn = await page.$('#type-fn')
}) expect(await typeFn.text()).toBe('fn: fn res')
} })
}) })
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/basic/define-slots/define-slots' const PAGE_PATH = '/pages/composition-api/basic/define-slots/define-slots'
describe('defineSlots', () => { describe('defineSlots', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const slotHeader = await page.$('#slot-header')
const slotHeader = await page.$('#slot-header') expect(await slotHeader.text()).toBe('header slot msg: foo msg')
expect(await slotHeader.text()).toBe('header slot msg: foo msg')
const slotContent = await page.$('#slot-default')
const slotContent = await page.$('#slot-default') expect(await slotContent.text()).toBe('default slot num: 0')
expect(await slotContent.text()).toBe('default slot num: 0')
const slotFooter = await page.$('#slot-footer')
const slotFooter = await page.$('#slot-footer') expect((await slotFooter.text()).replaceAll('\n', '')).toBe('footer slot arr: ["a","b","c"]')
expect(await slotFooter.text()).toBe('footer slot arr: ["a","b","c"]') })
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/basic/use-attrs/use-attrs' const PAGE_PATH = '/pages/composition-api/basic/use-attrs/use-attrs'
describe('useAttrs', () => { describe('useAttrs', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const attrsClass = await page.$('#attrs-class')
const attrsClass = await page.$('#attrs-class') expect(await attrsClass.text()).toBe('attrs.class: foo')
expect(await attrsClass.text()).toBe('attrs.class: foo')
const attrsMsg = await page.$('#attrs-msg')
expect(await attrsMsg.text()).toBe('attrs.msg: msg')
})
const attrsMsg = await page.$('#attrs-msg')
expect(await attrsMsg.text()).toBe('attrs.msg: msg')
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/reactivity/computed/computed' const PAGE_PATH = '/pages/composition-api/reactivity/computed/computed'
describe('computed', () => { describe('computed', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const count = await page.$('#count')
const count = await page.$('#count') expect(await count.text()).toBe('count: 0')
expect(await count.text()).toBe('count: 0') const doubleCount = await page.$('#double-count')
const doubleCount = await page.$('#double-count') expect(await doubleCount.text()).toBe('computed double count: 0')
expect(await doubleCount.text()).toBe('computed double count: 0')
const objArr = await page.$('#obj-arr') const objArr = await page.$('#obj-arr')
expect(await objArr.text()).toBe('obj.arr: [1,2,3]') expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [1,2,3]')
const objArrLen = await page.$('#obj-arr-len') const objArrLen = await page.$('#obj-arr-len')
expect(await objArrLen.text()).toBe('computed obj.arr.length: 3') expect(await objArrLen.text()).toBe('computed obj.arr.length: 3')
const updateBtn = await page.$('#update-btn') const updateBtn = await page.$('.update-btn')
await updateBtn.tap() await updateBtn.tap()
expect(await count.text()).toBe('count: 1')
expect(await doubleCount.text()).toBe('computed double count: 2')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [1,2,3,4]')
expect(await objArrLen.text()).toBe('computed obj.arr.length: 4')
})
expect(await count.text()).toBe('count: 1')
expect(await doubleCount.text()).toBe('computed double count: 2')
expect(await objArr.text()).toBe('obj.arr: [1,2,3,4]')
expect(await objArrLen.text()).toBe('computed obj.arr.length: 4')
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<text id="double-count" class="uni-common-mb">computed double count: {{ doubleCount }}</text> <text id="double-count" class="uni-common-mb">computed double count: {{ doubleCount }}</text>
<text id="obj-arr" class="uni-common-mb">obj.arr: {{ obj.arr }}</text> <text id="obj-arr" class="uni-common-mb">obj.arr: {{ obj.arr }}</text>
<text id="obj-arr-len" class="uni-common-mb">computed obj.arr.length: {{ objArrLen }}</text> <text id="obj-arr-len" class="uni-common-mb">computed obj.arr.length: {{ objArrLen }}</text>
<button id="update-btn" @click="update">update</button> <button class="update-btn" @click="update">update</button>
</view> </view>
</template> </template>
......
const PAGE_PATH = '/pages/composition-api/reactivity/is-ref/is-ref' const PAGE_PATH = '/pages/composition-api/reactivity/is-ref/is-ref'
describe('isRef', () => { describe('isRef', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const refCount = await page.$('#ref-count')
const refCount = await page.$('#ref-count') expect(await refCount.text()).toBe('ref count: 0')
expect(await refCount.text()).toBe('ref count: 0') const isRefRefCount = await page.$('#is-ref-ref-count')
const isRefRefCount = await page.$('#is-ref-ref-count') expect(await isRefRefCount.text()).toBe('isRef ref count: true')
expect(await isRefRefCount.text()).toBe('isRef ref count: true')
const count = await page.$('#count')
const count = await page.$('#count') expect(await count.text()).toBe('count: 0')
expect(await count.text()).toBe('count: 0') const isRefCount = await page.$('#is-ref-count')
const isRefCount = await page.$('#is-ref-count') expect(await isRefCount.text()).toBe('isRef count: false')
expect(await isRefCount.text()).toBe('isRef count: false') })
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/reactivity/ref/ref' const PAGE_PATH = '/pages/composition-api/reactivity/ref/ref'
describe('ref', () => { describe('ref', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const count1 = await page.$('#count1')
const count1 = await page.$('#count1') expect(await count1.text()).toBe('count1: 0')
expect(await count1.text()).toBe('count1: 0') const count2 = await page.$('#count2')
const count2 = await page.$('#count2') expect(await count2.text()).toBe('count2: 0')
expect(await count2.text()).toBe('count2: 0') const counterCount = await page.$('#counter-count')
const counterCount = await page.$('#counter-count') expect(await counterCount.text()).toBe('counter.count: 0')
expect(await counterCount.text()).toBe('counter.count: 0')
const incrementBtn = await page.$('#increment-btn') const incrementBtn = await page.$('.increment-btn')
await incrementBtn.tap() await incrementBtn.tap()
expect(await count1.text()).toBe('count1: 2')
expect(await count2.text()).toBe('count2: 2')
expect(await counterCount.text()).toBe('counter.count: 1')
})
expect(await count1.text()).toBe('count1: 2')
expect(await count2.text()).toBe('count2: 2')
expect(await counterCount.text()).toBe('counter.count: 1')
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<text id="count1" class="uni-common-mb">count1: {{ count1 }}</text> <text id="count1" class="uni-common-mb">count1: {{ count1 }}</text>
<text id="count2" class="uni-common-mb">count2: {{ count2 }}</text> <text id="count2" class="uni-common-mb">count2: {{ count2 }}</text>
<text id="counter-count" class="uni-common-mb">counter.count: {{ counter.count }}</text> <text id="counter-count" class="uni-common-mb">counter.count: {{ counter.count }}</text>
<button id="increment-btn" @click="increment">increment</button> <button class="increment-btn" @click="increment">increment</button>
</view> </view>
</template> </template>
......
const PAGE_PATH = '/pages/composition-api/reactivity/shallow-reactive/shallow-reactive' const PAGE_PATH = '/pages/composition-api/reactivity/shallow-reactive/shallow-reactive'
describe('shallowReactive', () => { describe('shallowReactive', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const stateCount = await page.$('#state-count')
const stateCount = await page.$('#state-count') expect(await stateCount.text()).toBe('state.count: 0')
expect(await stateCount.text()).toBe('state.count: 0')
const stateNestedCount = await page.$('#state-nested-count') const stateNestedCount = await page.$('#state-nested-count')
expect(await stateNestedCount.text()).toBe('state.nested.count: 0') expect(await stateNestedCount.text()).toBe('state.nested.count: 0')
const incrementStateNestedCountBtn = await page.$('#increment-state-nested-count-btn') const incrementStateNestedCountBtn = await page.$('.increment-state-nested-count-btn')
await incrementStateNestedCountBtn.tap() await incrementStateNestedCountBtn.tap()
expect(await stateNestedCount.text()).toBe('state.nested.count: 0') expect(await stateNestedCount.text()).toBe('state.nested.count: 0')
const incrementStateCountBtn = await page.$('#increment-state-count-btn') const incrementStateCountBtn = await page.$('.increment-state-count-btn')
await incrementStateCountBtn.tap() await incrementStateCountBtn.tap()
expect(await stateCount.text()).toBe('state.count: 1') expect(await stateCount.text()).toBe('state.count: 1')
expect(await stateNestedCount.text()).toBe('state.nested.count: 1') expect(await stateNestedCount.text()).toBe('state.nested.count: 1')
}) })
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
<template> <template>
<view class="page"> <view class="page">
<text id="state-count" class="uni-common-mb">state.count: {{ state.count }}</text> <text id="state-count" class="uni-common-mb" :data-count="state.count">state.count: {{ state.count }}</text>
<text id="state-nested-count" class="uni-common-mb">state.nested.count: {{ state.nested.count }}</text> <text id="state-nested-count" class="uni-common-mb">state.nested.count: {{ state.nested.count }}</text>
<button id="increment-state-count-btn" class="uni-common-mb" @click="incrementStateCount"> <button class="increment-state-count-btn uni-common-mb" @click="incrementStateCount">
increment state.count increment state.count
</button> </button>
<button id="increment-state-nested-count-btn" @click="incrementStateNestedCount"> <button class="increment-state-nested-count-btn" @click="incrementStateNestedCount">
increment state.nested.count increment state.nested.count
</button> </button>
</view> </view>
......
const PAGE_PATH = '/pages/composition-api/reactivity/shallow-ref/shallow-ref' const PAGE_PATH = '/pages/composition-api/reactivity/shallow-ref/shallow-ref'
describe('shallowRef', () => { describe('shallowRef', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const stateCount = await page.$('#state-count')
const stateCount = await page.$('#state-count') expect(await stateCount.text()).toBe('state.count: 0')
expect(await stateCount.text()).toBe('state.count: 0')
const incrementStateCountBtn = await page.$('.increment-state-count-btn')
const incrementStateCountBtn = await page.$('#increment-state-count-btn') await incrementStateCountBtn.tap()
await incrementStateCountBtn.tap()
expect(await stateCount.text()).toBe('state.count: 0')
expect(await stateCount.text()).toBe('state.count: 0')
const updateStateBtn = await page.$('.update-state-btn')
const updateStateBtn = await page.$('#update-state-btn') await updateStateBtn.tap()
await updateStateBtn.tap()
expect(await stateCount.text()).toBe('state.count: 1')
expect(await stateCount.text()).toBe('state.count: 1') })
})
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
<template> <template>
<view class="page"> <view class="page">
<text id="state-count" class="uni-common-mb">state.count: {{ state.count }}</text> <text id="state-count" class="uni-common-mb">state.count: {{ state.count }}</text>
<button id="increment-state-count-btn" class="uni-common-mb" @click="incrementStateCount">increment <button class="increment-state-count-btn uni-common-mb" @click="incrementStateCount">increment
state.count</button> state.count</button>
<button id="update-state-btn" @click="updateState">update state</button> <button class="update-state-btn" @click="updateState">update state</button>
</view> </view>
</template> </template>
......
const PAGE_PATH = '/pages/composition-api/reactivity/un-ref/un-ref' const PAGE_PATH = '/pages/composition-api/reactivity/un-ref/un-ref'
describe('unref', () => { describe('unref', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('basic', async () => {
it('basic', async () => { const refCount = await page.$('#ref-count')
const refCount = await page.$('#ref-count') expect(await refCount.text()).toBe('ref count: 0')
expect(await refCount.text()).toBe('ref count: 0') const refCountType = await page.$('#ref-count-type')
const refCountType = await page.$('#ref-count-type') expect(await refCountType.text()).toBe('ref count type: object')
expect(await refCountType.text()).toBe('ref count type: object')
const count = await page.$('#count') const count = await page.$('#count')
expect(await count.text()).toBe('count: 0') expect(await count.text()).toBe('count: 0')
const isRefCount = await page.$('#count-type') const isRefCount = await page.$('#count-type')
expect(await isRefCount.text()).toBe('count type: number') expect(await isRefCount.text()).toBe('count type: number')
}) })
} else {
it('other platform', () => {
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/reactivity/watch-effect/watch-effect' const PAGE_PATH = '/pages/composition-api/reactivity/watch-effect/watch-effect'
describe('watchEffect', () => { describe('watchEffect', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('count', async () => {
it('count', async () => { const count = await page.$('#count')
const count = await page.$('#count') expect(await count.text()).toBe('count: 0')
expect(await count.text()).toBe('count: 0')
// watch
// watch const watchCountRes = await page.$('#watch-count-res')
const watchCountRes = await page.$('#watch-count-res') if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchCountRes.text()).toBe( expect(await watchCountRes.text()).toBe(
'watch count result: count: 0, count ref text (flush sync): count: 0') 'watch count result: count: 0, count ref text (flush sync): count: 0')
}
// track if (process.env.uniTestPlatformInfo.startsWith('web')) {
const watchCountTrackNum = await page.$('#watch-count-track-num') expect(await watchCountRes.text()).toBe(
expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') 'watch count result: count: 0, count ref text (flush sync): null')
}
// trigger // track
const watchCountTriggerNum = await page.$('#watch-count-trigger-num') const watchCountTrackNum = await page.$('#watch-count-track-num')
expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 1') expect(await watchCountTrackNum.text()).toBe('watch count track number: 3')
const watchCountCleanupRes = await page.$('#watch-count-cleanup-res')
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 0') // trigger
const watchCountTriggerNum = await page.$('#watch-count-trigger-num')
// watch count and obj.num expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 1')
const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res') const watchCountCleanupRes = await page.$('#watch-count-cleanup-res')
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 0, obj.num: 0') expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 0')
const incrementBtn = await page.$('#increment-btn') // watch count and obj.num
await incrementBtn.tap() const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res')
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 0, obj.num: 0')
expect(await count.text()).toBe('count: 1')
const incrementBtn = await page.$('.increment-btn')
await incrementBtn.tap()
expect(await count.text()).toBe('count: 1')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchCountRes.text()).toBe( expect(await watchCountRes.text()).toBe(
'watch count result: count: 1, count ref text (flush sync): count: 0') 'watch count result: count: 1, count ref text (flush sync): count: 0')
expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') }
expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 2') if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 1') expect(await watchCountRes.text()).toBe(
'watch count result: count: 1, count ref text (flush sync): null')
}
expect(await watchCountTrackNum.text()).toBe('watch count track number: 3')
expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 2')
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 1')
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 1, obj.num: 0') expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 1, obj.num: 0')
await incrementBtn.tap() await incrementBtn.tap()
expect(await count.text()).toBe('count: 2') expect(await count.text()).toBe('count: 2')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchCountRes.text()).toBe( expect(await watchCountRes.text()).toBe(
'watch count result: count: 2, count ref text (flush sync): count: 1') 'watch count result: count: 2, count ref text (flush sync): count: 1')
expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') }
expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 3') if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2') expect(await watchCountRes.text()).toBe(
'watch count result: count: 2, count ref text (flush sync): null')
}
expect(await watchCountTrackNum.text()).toBe('watch count track number: 3')
expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 3')
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2')
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 2, obj.num: 0') expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 2, obj.num: 0')
// stop watch // stop watch
const stopWatchCountBtn = await page.$('#stop-watch-count-btn') const stopWatchCountBtn = await page.$('.stop-watch-count-btn')
await stopWatchCountBtn.tap() await stopWatchCountBtn.tap()
await incrementBtn.tap() await incrementBtn.tap()
expect(await count.text()).toBe('count: 3') expect(await count.text()).toBe('count: 3')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchCountRes.text()).toBe( expect(await watchCountRes.text()).toBe(
'watch count result: count: 2, count ref text (flush sync): count: 1') 'watch count result: count: 2, count ref text (flush sync): count: 1')
expect(await watchCountTrackNum.text()).toBe('watch count track number: 3') }
expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 3') if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2') expect(await watchCountRes.text()).toBe(
'watch count result: count: 2, count ref text (flush sync): null')
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 3, obj.num: 0') }
}) expect(await watchCountTrackNum.text()).toBe('watch count track number: 3')
it('obj', async () => { expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 3')
const objStr = await page.$('#obj-str') expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2')
expect(await objStr.text()).toBe('obj.str: num: 0')
const objNum = await page.$('#obj-num') expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 3, obj.num: 0')
expect(await objNum.text()).toBe('obj.num: 0') })
const objBool = await page.$('#obj-bool') it('obj', async () => {
expect(await objBool.text()).toBe('obj.bool: false') const objStr = await page.$('#obj-str')
const objArr = await page.$('#obj-arr') expect(await objStr.text()).toBe('obj.str: num: 0')
expect(await objArr.text()).toBe('obj.arr: [0]') const objNum = await page.$('#obj-num')
expect(await objNum.text()).toBe('obj.num: 0')
const watchObjRes = await page.$('#watch-obj-res') const objBool = await page.$('#obj-bool')
expect(await objBool.text()).toBe('obj.bool: false')
const objArr = await page.$('#obj-arr')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjRes.text()).toBe( expect(await watchObjRes.text()).toBe(
'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}') 'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}')
const watchObjStrRes = await page.$('#watch-obj-str-res') }
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchObjRes.text()).toBe(
'watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}')
}
const watchObjStrRes = await page.$('#watch-obj-str-res')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjStrRes.text()).toBe( expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 0, obj.str ref text (flush pre): obj.str: num: 0') 'watch obj.str result: str: num: 0, obj.str ref text (flush pre): obj.str: num: 0')
const watchObjBoolRes = await page.$('#watch-obj-bool-res') }
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 0, obj.str ref text (flush pre): null')
}
const watchObjBoolRes = await page.$('#watch-obj-bool-res')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjBoolRes.text()).toBe( expect(await watchObjBoolRes.text()).toBe(
'watch obj.bool result: bool: false, obj.bool ref text (flush post): obj.bool: false') 'watch obj.bool result: bool: false, obj.bool ref text (flush post): obj.bool: false')
const watchObjArrRes = await page.$('#watch-obj-arr-res') }
expect(await watchObjArrRes.text()).toBe('watch obj.arr result: arr: [0]') if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchObjBoolRes.text()).toBe(
'watch obj.bool result: bool: false, obj.bool ref text (flush post): null')
}
const watchObjArrRes = await page.$('#watch-obj-arr-res')
expect(await watchObjArrRes.text()).toBe('watch obj.arr result: arr: [0]')
const updateObjBtn = await page.$('#update-obj-btn') const updateObjBtn = await page.$('.update-obj-btn')
await updateObjBtn.tap() await updateObjBtn.tap()
expect(await objStr.text()).toBe('obj.str: num: 1') expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1') expect(await objNum.text()).toBe('obj.num: 1')
expect(await objBool.text()).toBe('obj.bool: true') expect(await objBool.text()).toBe('obj.bool: true')
expect(await objArr.text()).toBe('obj.arr: [0,1]') expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0,1]')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjRes.text()).toBe( expect(await watchObjRes.text()).toBe(
'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}') 'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}')
}
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchObjRes.text()).toBe(
'watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}')
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjStrRes.text()).toBe( expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 1, obj.str ref text (flush pre): obj.str: num: 0') 'watch obj.str result: str: num: 1, obj.str ref text (flush pre): obj.str: num: 0')
}
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 1, obj.str ref text (flush pre): null')
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjBoolRes.text()).toBe( expect(await watchObjBoolRes.text()).toBe(
'watch obj.bool result: bool: true, obj.bool ref text (flush post): obj.bool: true') 'watch obj.bool result: bool: true, obj.bool ref text (flush post): obj.bool: true')
expect(await watchObjArrRes.text()).toBe('watch obj.arr result: arr: [0,1]') }
if (process.env.uniTestPlatformInfo.startsWith('web')) {
const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res') expect(await watchObjBoolRes.text()).toBe(
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 3, obj.num: 1') 'watch obj.bool result: bool: true, obj.bool ref text (flush post): null')
}) }
} else { expect(await watchObjArrRes.text()).toBe('watch obj.arr result: arr: [0,1]')
it('other platform', () => {
expect(1).toBe(1) const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res')
}) expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: count: 3, obj.num: 1')
} })
}) })
\ No newline at end of file
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
{{ watchCountTriggerNum }}</text> {{ watchCountTriggerNum }}</text>
<text id="watch-count-cleanup-res" class="uni-common-mb">watch count cleanup result: <text id="watch-count-cleanup-res" class="uni-common-mb">watch count cleanup result:
{{ watchCountCleanupRes }}</text> {{ watchCountCleanupRes }}</text>
<button id="increment-btn" class="uni-common-mb" @click="increment"> <button class="increment-btn uni-common-mb" @click="increment">
increment increment
</button> </button>
<button id="stop-watch-count-btn" class="uni-common-mb" @click="triggerStopWatchCount"> <button class="stop-watch-count-btn uni-common-mb" @click="triggerStopWatchCount">
stop watch count stop watch count
</button> </button>
<text id="obj-str" ref="objStrRef" class="uni-common-mb">obj.str: {{ obj.str }}</text> <text id="obj-str" ref="objStrRef" class="uni-common-mb">obj.str: {{ obj.str }}</text>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<text id="watch-obj-str-res" class="uni-common-mb">watch obj.str result: {{ watchObjStrRes }}</text> <text id="watch-obj-str-res" class="uni-common-mb">watch obj.str result: {{ watchObjStrRes }}</text>
<text id="watch-obj-bool-res" class="uni-common-mb">watch obj.bool result: {{ watchObjBoolRes }}</text> <text id="watch-obj-bool-res" class="uni-common-mb">watch obj.bool result: {{ watchObjBoolRes }}</text>
<text id="watch-obj-arr-res" class="uni-common-mb">watch obj.arr result: {{ watchObjArrRes }}</text> <text id="watch-obj-arr-res" class="uni-common-mb">watch obj.arr result: {{ watchObjArrRes }}</text>
<button id="update-obj-btn" class="uni-common-mb" @click="updateObj"> <button class="update-obj-btn uni-common-mb" @click="updateObj">
update obj update obj
</button> </button>
<text id="watch-count-obj-num-res" class="uni-common-mb">watch count and obj.num result: <text id="watch-count-obj-num-res" class="uni-common-mb">watch count and obj.num result:
......
const PAGE_PATH = '/pages/composition-api/reactivity/watch/watch' const PAGE_PATH = '/pages/composition-api/reactivity/watch/watch'
describe('watch', () => { describe('watch', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.reLaunch(PAGE_PATH)
page = await program.reLaunch(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
}) it('count', async () => {
it('count', async () => { const count = await page.$('#count')
const count = await page.$('#count') expect(await count.text()).toBe('count: 0')
expect(await count.text()).toBe('count: 0')
// watch
// watch const watchCountRes = await page.$('#watch-count-res')
const watchCountRes = await page.$('#watch-count-res') expect((await watchCountRes.text()).trim()).toBe('watch count result:')
expect(await watchCountRes.text()).toBe('watch count result: ')
// track
// track const watchCountTrackNum = await page.$('#watch-count-track-num')
const watchCountTrackNum = await page.$('#watch-count-track-num') expect(await watchCountTrackNum.text()).toBe('watch count track number: 2')
expect(await watchCountTrackNum.text()).toBe('watch count track number: 2')
// trigger
// trigger const watchCountTriggerNum = await page.$('#watch-count-trigger-num')
const watchCountTriggerNum = await page.$('#watch-count-trigger-num') expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 0')
expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 0') const watchCountCleanupRes = await page.$('#watch-count-cleanup-res')
const watchCountCleanupRes = await page.$('#watch-count-cleanup-res') expect((await watchCountCleanupRes.text()).trim()).toBe('watch count cleanup result:')
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: ')
// watch count and obj.num
// watch count and obj.num const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res')
const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res') expect((await watchCountAndObjNumRes.text()).trim()).toBe('watch count and obj.num result:')
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: ')
const incrementBtn = await page.$('.increment-btn')
const incrementBtn = await page.$('#increment-btn') await incrementBtn.tap()
await incrementBtn.tap()
expect(await count.text()).toBe('count: 1')
expect(await count.text()).toBe('count: 1')
expect(await watchCountRes.text()).toBe('watch count result: count: 1, prevCount: 0, count ref text (flush sync): count: 0') if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchCountTrackNum.text()).toBe('watch count track number: 2') expect(await watchCountRes.text()).toBe(
expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 1') 'watch count result: count: 1, prevCount: 0, count ref text (flush sync): count: 0')
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: ') }
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: state: [1,0], preState: [0,0]') expect(await watchCountRes.text()).toBe(
'watch count result: count: 1, prevCount: 0, count ref text (flush sync): null')
await incrementBtn.tap() }
expect(await count.text()).toBe('count: 2') expect(await watchCountTrackNum.text()).toBe('watch count track number: 2')
expect(await watchCountRes.text()).toBe('watch count result: count: 2, prevCount: 1, count ref text (flush sync): count: 1') expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 1')
expect(await watchCountTrackNum.text()).toBe('watch count track number: 2') expect((await watchCountCleanupRes.text()).trim()).toBe('watch count cleanup result:')
expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 2')
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 1') expect(await watchCountAndObjNumRes.text()).toBe(
'watch count and obj.num result: state: [1,0], preState: [0,0]')
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: state: [2,0], preState: [1,0]')
await incrementBtn.tap()
// stop watch
const stopWatchCountBtn = await page.$('#stop-watch-count-btn') expect(await count.text()).toBe('count: 2')
await stopWatchCountBtn.tap() if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchCountRes.text()).toBe(
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2') 'watch count result: count: 2, prevCount: 1, count ref text (flush sync): count: 1')
}
await incrementBtn.tap() if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchCountRes.text()).toBe(
expect(await count.text()).toBe('count: 3') 'watch count result: count: 2, prevCount: 1, count ref text (flush sync): null')
expect(await watchCountRes.text()).toBe('watch count result: count: 2, prevCount: 1, count ref text (flush sync): count: 1')
expect(await watchCountTrackNum.text()).toBe('watch count track number: 2') }
expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 2') expect(await watchCountTrackNum.text()).toBe('watch count track number: 2')
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2') expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 2')
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 1')
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: state: [3,0], preState: [2,0]')
}) expect(await watchCountAndObjNumRes.text()).toBe(
it('obj', async () => { 'watch count and obj.num result: state: [2,0], preState: [1,0]')
const objStr = await page.$('#obj-str')
expect(await objStr.text()).toBe('obj.str: num: 0') // stop watch
const objNum = await page.$('#obj-num') const stopWatchCountBtn = await page.$('.stop-watch-count-btn')
expect(await objNum.text()).toBe('obj.num: 0') await stopWatchCountBtn.tap()
const objBool = await page.$('#obj-bool')
expect(await objBool.text()).toBe('obj.bool: false') expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2')
const objArr = await page.$('#obj-arr')
expect(await objArr.text()).toBe('obj.arr: [0]') await incrementBtn.tap()
const watchObjRes = await page.$('#watch-obj-res') expect(await count.text()).toBe('count: 3')
expect(await watchObjRes.text()).toBe('watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}, prevObj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}') if (process.env.uniTestPlatformInfo.startsWith('android')) {
const watchObjStrRes = await page.$('#watch-obj-str-res') expect(await watchCountRes.text()).toBe(
expect(await watchObjStrRes.text()).toBe('watch obj.str result: ') 'watch count result: count: 2, prevCount: 1, count ref text (flush sync): count: 1')
const watchObjBoolRes = await page.$('#watch-obj-bool-res') }
expect(await watchObjBoolRes.text()).toBe('watch obj.bool result: ') if (process.env.uniTestPlatformInfo.startsWith('web')) {
const watchObjArrRes = await page.$('#watch-obj-arr-res') expect(await watchCountRes.text()).toBe(
expect(await watchObjArrRes.text()).toBe('watch obj.arr result: ') 'watch count result: count: 2, prevCount: 1, count ref text (flush sync): null')
}
const updateObjBtn = await page.$('#update-obj-btn') expect(await watchCountTrackNum.text()).toBe('watch count track number: 2')
await updateObjBtn.tap() expect(await watchCountTriggerNum.text()).toBe('watch count trigger number: 2')
expect(await watchCountCleanupRes.text()).toBe('watch count cleanup result: watch count cleanup: 2')
expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1') expect(await watchCountAndObjNumRes.text()).toBe(
expect(await objBool.text()).toBe('obj.bool: true') 'watch count and obj.num result: state: [3,0], preState: [2,0]')
expect(await objArr.text()).toBe('obj.arr: [0,1]') })
it('obj', async () => {
expect(await watchObjRes.text()).toBe('watch obj result: obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}, prevObj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}') const objStr = await page.$('#obj-str')
expect(await watchObjStrRes.text()).toBe('watch obj.str result: str: num: 1, prevStr: num: 0, obj.str ref text (flush pre): obj.str: num: 0') expect(await objStr.text()).toBe('obj.str: num: 0')
expect(await watchObjBoolRes.text()).toBe('watch obj.bool result: bool: true, prevBool: false, obj.bool ref text (flush post): obj.bool: true') const objNum = await page.$('#obj-num')
expect(await watchObjArrRes.text()).toBe('watch obj.arr result: arr: [0,1], prevArr: [0,1]') expect(await objNum.text()).toBe('obj.num: 0')
const objBool = await page.$('#obj-bool')
const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res') expect(await objBool.text()).toBe('obj.bool: false')
expect(await watchCountAndObjNumRes.text()).toBe('watch count and obj.num result: state: [3,1], preState: [3,0]') const objArr = await page.$('#obj-arr')
}) expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0]')
} else {
it('other platform', () => { const watchObjRes = await page.$('#watch-obj-res')
expect(1).toBe(1) if (process.env.uniTestPlatformInfo.startsWith('android')) {
}) expect(await watchObjRes.text()).toBe(
} 'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}, prevObj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}'
)
}
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchObjRes.text()).toBe(
'watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}, prevObj: null'
)
}
const watchObjStrRes = await page.$('#watch-obj-str-res')
expect((await watchObjStrRes.text()).trim()).toBe('watch obj.str result:')
const watchObjBoolRes = await page.$('#watch-obj-bool-res')
expect((await watchObjBoolRes.text()).trim()).toBe('watch obj.bool result:')
const watchObjArrRes = await page.$('#watch-obj-arr-res')
expect((await watchObjArrRes.text()).trim()).toBe('watch obj.arr result:')
const updateObjBtn = await page.$('.update-obj-btn')
await updateObjBtn.tap()
expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1')
expect(await objBool.text()).toBe('obj.bool: true')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0,1]')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjRes.text()).toBe(
'watch obj result: obj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}, prevObj: {"arr":[0,1],"bool":true,"num":1,"str":"num: 1"}'
)
}
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchObjRes.text()).toBe(
'watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}, prevObj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}'
)
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 1, prevStr: num: 0, obj.str ref text (flush pre): obj.str: num: 0')
}
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 1, prevStr: num: 0, obj.str ref text (flush pre): null')
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjBoolRes.text()).toBe(
'watch obj.bool result: bool: true, prevBool: false, obj.bool ref text (flush post): obj.bool: true'
)
}
if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(await watchObjBoolRes.text()).toBe(
'watch obj.bool result: bool: true, prevBool: false, obj.bool ref text (flush post): null')
}
expect(await watchObjArrRes.text()).toBe('watch obj.arr result: arr: [0,1], prevArr: [0,1]')
const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res')
expect(await watchCountAndObjNumRes.text()).toBe(
'watch count and obj.num result: state: [3,1], preState: [3,0]')
})
}) })
\ No newline at end of file
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
{{ watchCountTriggerNum }}</text> {{ watchCountTriggerNum }}</text>
<text id="watch-count-cleanup-res" class="uni-common-mb">watch count cleanup result: <text id="watch-count-cleanup-res" class="uni-common-mb">watch count cleanup result:
{{ watchCountCleanupRes }}</text> {{ watchCountCleanupRes }}</text>
<button id="increment-btn" class="uni-common-mb" @click="increment"> <button class="increment-btn uni-common-mb" @click="increment">
increment increment
</button> </button>
<button id="stop-watch-count-btn" class="uni-common-mb" @click="triggerStopWatchCount"> <button class="stop-watch-count-btn uni-common-mb" @click="triggerStopWatchCount">
stop watch count stop watch count
</button> </button>
<text id="obj-str" ref="objStrRef" class="uni-common-mb">obj.str: {{ obj.str }}</text> <text id="obj-str" ref="objStrRef" class="uni-common-mb">obj.str: {{ obj.str }}</text>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<text id="watch-obj-str-res" class="uni-common-mb">watch obj.str result: {{ watchObjStrRes }}</text> <text id="watch-obj-str-res" class="uni-common-mb">watch obj.str result: {{ watchObjStrRes }}</text>
<text id="watch-obj-bool-res" class="uni-common-mb">watch obj.bool result: {{ watchObjBoolRes }}</text> <text id="watch-obj-bool-res" class="uni-common-mb">watch obj.bool result: {{ watchObjBoolRes }}</text>
<text id="watch-obj-arr-res" class="uni-common-mb">watch obj.arr result: {{ watchObjArrRes }}</text> <text id="watch-obj-arr-res" class="uni-common-mb">watch obj.arr result: {{ watchObjArrRes }}</text>
<button id="update-obj-btn" class="uni-common-mb" @click="updateObj"> <button class="update-obj-btn uni-common-mb" @click="updateObj">
update obj update obj
</button> </button>
<text id="watch-count-obj-num-res" class="uni-common-mb">watch count and obj.num result: <text id="watch-count-obj-num-res" class="uni-common-mb">watch count and obj.num result:
......
...@@ -35,196 +35,292 @@ ...@@ -35,196 +35,292 @@
url ?: string url ?: string
enable ?: boolean enable ?: boolean
} }
const list = [ const list = [
{ {
id: 'basic', id: 'basic',
name: '基本使用', name: '基本使用',
open: false, open: false,
pages: [ pages: [
{ {
name: 'defineProps', name: 'defineProps',
url: 'define-props', url: 'define-props',
enable: false, enable: true,
}, },
{ {
name: 'defineEmits', name: 'defineEmits',
url: 'define-emits', url: 'define-emits',
enable: true, enable: true,
}, },
{ {
name: 'defineExpose', name: 'defineExpose',
url: 'define-expose', url: 'define-expose',
enable: true, // #ifdef APP
}, enable: true,
{ // #endif
name: 'defineOptions', // #ifdef WEB
url: 'define-options', enable: false,
enable: true, // #endif
}, },
{ {
name: 'defineSlots', name: 'defineOptions',
url: 'define-slots', url: 'define-options',
enable: true, enable: true,
}, },
{ {
name: 'defineModel', name: 'defineSlots',
url: 'define-model', url: 'define-slots',
enable: true, enable: true,
}, },
{ {
name: 'useSlots', name: 'defineModel',
url: 'use-slots', url: 'define-model',
enable: true, // #ifdef APP
}, enable: true,
{ // #endif
name: 'useAttrs', // #ifdef WEB
url: 'use-attrs', enable: false,
enable: true, // #endif
}, },
] as PageItem[], {
}, { name: 'useSlots',
id: 'reactivity', url: 'use-slots',
name: '响应式', // #ifdef APP
open: false, enable: true,
pages: [ // #endif
{ // #ifdef WEB
name: 'ref', enable: false,
url: 'ref', // #endif
enable: true, },
}, {
{ name: 'useAttrs',
name: 'computed', url: 'use-attrs',
url: 'computed', enable: true,
enable: true, },
}, ] as PageItem[],
{ }, {
name: 'reactive', id: 'reactivity',
url: 'reactive', name: '响应式',
enable: true, open: false,
}, pages: [
{ {
name: 'readonly', name: 'ref',
url: 'readonly', url: 'ref',
enable: true, enable: true,
}, },
{ {
name: 'watch', name: 'computed',
url: 'watch', url: 'computed',
enable: true, enable: true,
}, },
{ {
name: 'watchEffect', name: 'reactive',
url: 'watch-effect', url: 'reactive',
enable: true, // #ifdef APP
}, enable: true,
{ // #endif
name: 'watchPostEffect', // #ifdef WEB
url: 'watch-post-effect', enable: false,
enable: true, // #endif
}, },
{ {
name: 'watchSyncEffect', name: 'readonly',
url: 'watch-sync-effect', url: 'readonly',
enable: true, // #ifdef APP
}, enable: true,
{ // #endif
name: 'isRef', // #ifdef WEB
url: 'is-ref', enable: false,
enable: true, // #endif
}, },
{ {
name: 'unRef', name: 'watch',
url: 'un-ref', url: 'watch',
enable: true, enable: true,
}, },
{ {
name: 'toRef', name: 'watchEffect',
url: 'to-ref', url: 'watch-effect',
enable: true, enable: true,
}, },
{ {
name: 'toValue', name: 'watchPostEffect',
url: 'to-value', url: 'watch-post-effect',
// #ifdef APP // #ifdef APP
enable: true, enable: true,
// #else // #endif
enable: false, // #ifdef WEB
// #endif enable: false,
}, // #endif
{ },
name: 'toRefs', {
url: 'to-refs', name: 'watchSyncEffect',
enable: true, url: 'watch-sync-effect',
}, // #ifdef APP
{ enable: true,
name: 'isProxy', // #endif
url: 'is-proxy', // #ifdef WEB
enable: true, enable: false,
}, // #endif
{ },
name: 'isReactive', {
url: 'is-reactive', name: 'isRef',
enable: true, url: 'is-ref',
}, enable: true,
{ },
name: 'isReadonly', {
url: 'is-readonly', name: 'unRef',
enable: true, url: 'un-ref',
}, enable: true,
{ },
name: 'shallowRef', {
url: 'shallow-ref', name: 'toRef',
enable: true, url: 'to-ref',
}, // #ifdef APP
{ enable: true,
name: 'triggerRef', // #endif
url: 'trigger-ref', // #ifdef WEB
enable: true, enable: false,
}, // #endif
{ },
name: 'customRef', {
url: 'custom-ref', name: 'toValue',
enable: true, url: 'to-value',
}, // #ifdef APP
{ enable: true,
name: 'shallowReactive', // #endif
url: 'shallow-reactive', // #ifdef WEB
enable: true, enable: false,
}, // #endif
{ },
name: 'shallowReadonly', {
url: 'shallow-readonly', name: 'toRefs',
enable: true, url: 'to-refs',
}, // #ifdef APP
{ enable: true,
name: 'toRaw', // #endif
url: 'to-raw', // #ifdef WEB
enable: true, enable: false,
}, // #endif
{ },
name: 'markRaw', {
url: 'mark-raw', name: 'isProxy',
enable: false, // 暂不支持 url: 'is-proxy',
}, // #ifdef APP
{ enable: true,
name: 'effectScope', // #endif
url: 'effect-scope', // #ifdef WEB
enable: true, enable: false,
}, // #endif
{ },
name: 'getCurrentScope', {
url: 'get-current-scope', name: 'isReactive',
enable: true, url: 'is-reactive',
}, // #ifdef APP
{ enable: true,
name: 'onScopeDispose', // #endif
url: 'on-scope-dispose', // #ifdef WEB
enable: true, enable: false,
}, // #endif
] as PageItem[], },
} {
] as PageList[] name: 'isReadonly',
url: 'is-readonly',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'shallowRef',
url: 'shallow-ref',
enable: true,
},
{
name: 'triggerRef',
url: 'trigger-ref',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'customRef',
url: 'custom-ref',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'shallowReactive',
url: 'shallow-reactive',
enable: true,
},
{
name: 'shallowReadonly',
url: 'shallow-readonly',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'toRaw',
url: 'to-raw',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'markRaw',
url: 'mark-raw',
enable: false, // 暂不支持
},
{
name: 'effectScope',
url: 'effect-scope',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'getCurrentScope',
url: 'get-current-scope',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
{
name: 'onScopeDispose',
url: 'on-scope-dispose',
// #ifdef APP
enable: true,
// #endif
// #ifdef WEB
enable: false,
// #endif
},
] as PageItem[],
}
] as PageList[]
const goDetailPage = (id : string, e : PageItem) => { const goDetailPage = (id : string, e : PageItem) => {
if (e.enable == false) { if (e.enable == false) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册