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

test(component lifecycle): 优化示例,兼容 web 端

上级 fb22177e
<template> <template>
<view> title: {{ title }}
<text>{{ title }}</text> <button class="component-lifecycle-btn" @click="updateTitle">updateTitle</button>
</view>
</template> </template>
<script lang="ts"> <script lang="ts">
...@@ -54,10 +53,9 @@ export default { ...@@ -54,10 +53,9 @@ export default {
console.log('component for lifecycle test unmounted') console.log('component for lifecycle test unmounted')
}, },
methods: { methods: {
// 自动化测试 updateTitle(){
getLifeCycleNum(): number { this.title = 'component for lifecycle test updated'
return state.lifeCycleNum }
},
}, },
} }
</script> </script>
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
}) })
this.myGlobalProperties.map = {} this.myGlobalProperties.map = {}
this.globalPropertiesMap.forEach((value, key) => { this.globalPropertiesMap.forEach((value, key) => {
this.myGlobalProperties.map[key!] = value this.myGlobalProperties.map[key] = value
}) })
this.myGlobalProperties.reactiveObj = this.globalPropertiesReactiveObj this.myGlobalProperties.reactiveObj = this.globalPropertiesReactiveObj
this.globalPropertiesFnRes = this.globalPropertiesFn() this.globalPropertiesFnRes = this.globalPropertiesFn()
......
...@@ -27,23 +27,14 @@ describe('component-lifecycle', () => { ...@@ -27,23 +27,14 @@ describe('component-lifecycle', () => {
expect(lifeCycleNum).toBe(4) expect(lifeCycleNum).toBe(4)
}) })
it('beforeUpdate updated', async () => { it('beforeUpdate updated', async () => {
// TODO: web 端组件更新不触发 updated,待修复后调整测试例 const updateTitleBtn = await page.$('.component-lifecycle-btn')
if (process.env.uniTestPlatformInfo.startsWith('android')) { await updateTitleBtn.tap()
const component = await page.$('.component-lifecycle')
await component.setData({
title: 'component for lifecycle test new title'
})
lifeCycleNum = await page.callMethod('getLifeCycleNum') lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(6) expect(lifeCycleNum).toBe(6)
}
}) })
it('beforeUnmount unmounted', async () => { it('beforeUnmount unmounted', async () => {
page = await program.navigateBack() page = await program.navigateBack()
lifeCycleNum = await page.callMethod('getLifeCycleNum') lifeCycleNum = await page.callMethod('getLifeCycleNum')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(lifeCycleNum).toBe(4) expect(lifeCycleNum).toBe(4)
}else{
expect(lifeCycleNum).toBe(2)
}
}) })
}) })
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册