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

test: 补充 app onLaunch、onShow 参数测试

上级 e0d93c28
<script lang="ts">
import { state, setLifeCycleNum } from './store/index.uts'
<script lang="uts">
import { state, setLifeCycleNum, setAppLaunchPath, setAppShowPath } from './store/index.uts'
let firstBackTime = 0
export default {
onLaunch: function () {
onLaunch: function (options) {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1000)
setAppLaunchPath(options.path)
console.log('App Launch')
const performance = uni.getPerformance()
......@@ -17,9 +18,10 @@ export default {
entryTypes: ['render', 'navigation'],
} as PerformanceObserverOptions)
},
onShow: function () {
onShow: function (options) {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 100)
setAppShowPath(options.path)
console.log('App Show')
},
onHide: function () {
......@@ -48,6 +50,18 @@ export default {
onExit() {
console.log('App Exit')
},
methods: {
checkLaunchPath(): boolean{
const HOME_PATH = '/pages/index'
if(state.appLaunchPath != HOME_PATH){
return false
}
if(state.appShowPath != HOME_PATH){
return false
}
return true
}
}
}
</script>
......
describe("app lanch & show options", () => {
it("onLaunch onShow", async () => {
const HOME_PATH = "/pages/index"
const page = await program.reLaunch(HOME_PATH)
await page.waitFor(1000)
expect(await page.callMethod("checkLaunchPath")).toBe(true)
})
})
......@@ -16,13 +16,13 @@
</view>
</view>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
<script lang="uts">
import { setLifeCycleNum, state } from '@/store/index.uts'
type PageItem = {
......@@ -353,10 +353,15 @@
setLifeCycleNum(num : number) {
setLifeCycleNum(num)
},
// 自动化测试
getLifeCycleNum() : number {
return state.lifeCycleNum
},
// 自动化测试
getLifeCycleNum() : number {
return state.lifeCycleNum
},
// 自动化测试
checkLaunchPath() : boolean {
const app = getApp()
return app.checkLaunchPath()
},
},
}
</script>
......
export type State = {
lifeCycleNum: number
componentMsg: number
lifeCycleNum: number
componentMsg: number,
appLaunchPath: string
appShowPath: string
}
export const state = reactive({
lifeCycleNum: 0,
componentMsg: 0
lifeCycleNum: 0,
componentMsg: 0,
appLaunchPath: '',
appShowPath: '',
} as State)
export const setLifeCycleNum = (num: number) => {
......@@ -14,3 +18,11 @@ export const setLifeCycleNum = (num: number) => {
export const setComponentMsg = (msg: number) => {
state.componentMsg = msg
}
export const setAppLaunchPath = (path: string) => {
state.appLaunchPath = path
}
export const setAppShowPath = (path: string) => {
state.appShowPath = path
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册