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

test: 补充 onError 测试例

上级 e2305ee4
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
// #endif // #endif
onError: function(error: any) { onError: function(error: any) {
console.log('App Error', error) console.log('App Error', error)
setLifeCycleNum(state.lifeCycleNum + 100)
}, },
methods: { methods: {
checkLaunchPath() : boolean { checkLaunchPath() : boolean {
......
<template> <template>
<view class="page"> <view class="page">
<button @click="triggerError">trigger error</button> <button id="trigger-error" @click="triggerError">trigger error</button>
</view> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { state } from '@/store/index.uts'
onReady(() => { onReady(() => {
throw Error('error in error composition page onReady') throw Error('error in error composition page onReady')
}) })
const triggerError = () => { const triggerError = () => {
throw Error('trigger error in throw error composition page') throw Error('trigger error in throw error composition page')
} }
// 自动化测试
const getLifeCycleNum = () : number => {
return state.lifeCycleNum
}
defineExpose({
getLifeCycleNum
})
</script> </script>
\ No newline at end of file
<template> <template>
<view class="page"> <view class="page">
<button @click="triggerError">trigger error</button> <button id="trigger-error" @click="triggerError">trigger error</button>
</view> </view>
</template> </template>
<script lang="uts"> <script lang="uts">
import { state } from '@/store/index.uts'
export default { export default {
onReady(){ onReady(){
throw Error('error in error options page onReady') throw Error('error in error options page onReady')
...@@ -12,6 +14,10 @@ export default { ...@@ -12,6 +14,10 @@ export default {
methods: { methods: {
triggerError(){ triggerError(){
throw Error('trigger error in throw error options page') throw Error('trigger error in throw error options page')
},
// 自动化测试
getLifeCycleNum() : number {
return state.lifeCycleNum
} }
}, },
} }
......
const OPTIONS_PAGE_PATH = '/pages/error/throw-error/throw-error-options'
const COMPOSITION_PAGE_PATH = '/pages/error/throw-error/throw-error-composition'
const HOME_PAGE_PATH = '/pages/index/index'
describe('throw error', () => {
let page
let lifeCycleNum
const initLifecycle = async () => {
page = await program.reLaunch(HOME_PAGE_PATH)
await page.waitFor('view')
await page.callMethod('setLifeCycleNum', 0)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(0)
}
const test = async (pagePath) => {
await initLifecycle()
page = await program.reLaunch(pagePath)
await page.waitFor('view')
expect(page.path).toBe(pagePath.substring(1))
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(100)
const triggerErrorBtn = await page.$('#trigger-error')
await triggerErrorBtn.tap()
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(200)
page = await program.navigateTo(HOME_PAGE_PATH)
await page.waitFor('view')
expect(page.path).toBe(HOME_PAGE_PATH.substring(1))
}
it('onError options API', async () => {
await test(OPTIONS_PAGE_PATH)
})
it('onError composition API', async () => {
await test(COMPOSITION_PAGE_PATH)
})
afterAll(async () => {
const resetLifecycleNum = 1100
await page.callMethod('setLifeCycleNum', resetLifecycleNum)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(resetLifecycleNum)
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册