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