提交 a7d9aa1d 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io
...@@ -32,8 +32,15 @@ export default { ...@@ -32,8 +32,15 @@ export default {
onLastPageBackPress: function (): boolean | null { onLastPageBackPress: function (): boolean | null {
// 自动化测试 // 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1000) setLifeCycleNum(state.lifeCycleNum - 1000)
console.log('App LastPageBackPress')
return null return null
}, },
methods: {
increasetLifeCycleNum() {
setLifeCycleNum(state.lifeCycleNum + 100)
console.log('App increasetLifeCycleNum')
}
}
} }
</script> </script>
......
...@@ -4,8 +4,9 @@ describe('getApp', () => { ...@@ -4,8 +4,9 @@ describe('getApp', () => {
it('getApp', async () => { it('getApp', async () => {
const page = await program.navigateTo(PAGE_PATH) const page = await program.navigateTo(PAGE_PATH)
await page.waitFor(1000) await page.waitFor(1000)
await page.callMethod('_getApp') const oldData = await page.data()
const data = await page.data() await page.callMethod('_increasetLifeCycleNum')
expect(data.checked).toBe(true) const newData = await page.data()
expect(newData.lifeCycleNum - oldData.lifeCycleNum).toBe(100)
}) })
}) })
<template> <template>
<view> <view>
<page-head title="getApp"></page-head> <page-head title="getApp"></page-head>
<button @click="_getApp">getApp</button> <view class="uni-padding-wrap">
<button @click="_increasetLifeCycleNum">increase lifeCycleNum</button>
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
</view>
</view> </view>
</template> </template>
<script> <script lang="ts">
export default { import { state } from '@/store/index.uts'
export default {
data() { data() {
return { return {
checked: false lifeCycleNum: 0,
} }
}, },
onReady() {
this.lifeCycleNum = state.lifeCycleNum
},
methods: { methods: {
_getApp: function () { _increasetLifeCycleNum: function () {
// const app = getApp() const app = getApp()
this.checked = true app.increasetLifeCycleNum()
} this.lifeCycleNum = state.lifeCycleNum
} },
} },
}
</script> </script>
<template> <template>
<view> <view>
<page-head title="getCurrentPages"></page-head> <page-head title="getCurrentPages"></page-head>
<view class="uni-padding-wrap">
<button @click="_getCurrentPages">getCurrentPages</button> <button @click="_getCurrentPages">getCurrentPages</button>
<button class="uni-common-mt" @click="hideAndShow">页面隐藏并显示</button> <button class="uni-common-mt" @click="hideAndShow">页面隐藏并显示</button>
<view style="padding: 15px 10px"> <view style="padding: 15px 0px">
<text>当前页面栈中 {{pages.length}} 个页面,列表如下:</text> <text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text>
<template v-for="(page, index) in pages" :key="page.route"> <template v-for="(page, index) in pages" :key="page.route">
<text style="margin-top: 5px" <text style="margin-top: 5px"
>index: {{ index }}, route: {{ page.route }}</text >index: {{ index }}, route: {{ page.route }}</text
...@@ -12,6 +13,7 @@ ...@@ -12,6 +13,7 @@
</template> </template>
</view> </view>
</view> </view>
</view>
</template> </template>
<script> <script>
class Page { class Page {
......
...@@ -51,6 +51,36 @@ describe('navigator', () => { ...@@ -51,6 +51,36 @@ describe('navigator', () => {
await page.waitFor(1000) await page.waitFor(1000)
}) })
it('navigateTo relative path', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateToRelativePath1')
page = await program.navigateBack()
await page.waitFor(1000)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
await page.waitFor(1000)
})
it('navigateTo relative path ./', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateToRelativePath2')
page = await program.navigateBack()
await page.waitFor(1000)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
await page.waitFor(1000)
})
it('navigateTo relative path ../', async () => {
await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateToRelativePath3')
page = await program.navigateBack()
await page.waitFor(1000)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(2)
await page.waitFor(1000)
})
it('navigateBack', async () => { it('navigateBack', async () => {
await page.callMethod('setLifeCycleNum', 0) await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('navigateBack') await page.callMethod('navigateBack')
......
...@@ -175,6 +175,51 @@ export default { ...@@ -175,6 +175,51 @@ export default {
}, },
}) })
}, },
// 自动化测试
navigateToRelativePath1() {
uni.navigateTo({
url: 'new-page/new-page-1?data=new-page/new-page-1',
success() {
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail() {
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete() {
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
},
// 自动化测试
navigateToRelativePath2() {
uni.navigateTo({
url: './new-page/new-page-1?data=./new-page/new-page-1',
success() {
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail() {
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete() {
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
},
// 自动化测试
navigateToRelativePath3() {
uni.navigateTo({
url: '../navigator/new-page/new-page-1?data=../navigator/new-page/new-page-1',
success() {
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail() {
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete() {
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
},
navigateBack() { navigateBack() {
uni.navigateBack({ uni.navigateBack({
success(result) { success(result) {
......
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
{ {
name: "getApp", name: "getApp",
url: "get-app", url: "get-app",
enable: false
}, },
{ {
name: "getCurrentPages", name: "getCurrentPages",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册