Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
23f789b1
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6068
Star
93
Fork
166
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
23f789b1
编写于
8月 02, 2023
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test(API): navigateBack delta
上级
cf481cf3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
98 addition
and
40 deletion
+98
-40
pages/API/navigator/navigator.test.js
pages/API/navigator/navigator.test.js
+48
-39
pages/API/navigator/navigator.uvue
pages/API/navigator/navigator.uvue
+50
-0
pages/API/navigator/new-page/new-page-1.uvue
pages/API/navigator/new-page/new-page-1.uvue
+0
-1
未找到文件。
pages/API/navigator/navigator.test.js
浏览文件 @
23f789b1
jest
.
setTimeout
(
40000
)
const
CURRENT_PAGE_PATH
=
'
/pages/API/navigator/navigator
'
const
HOME_PAGE_PATH
=
'
/pages/tabBar/component
'
describe
(
'
navigator
'
,
()
=>
{
let
page
let
lifeCycleNum
afterAll
(
async
()
=>
{
const
resetLifecycleNum
=
1100
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
resetLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
resetLifecycleNum
)
})
it
(
'
reLaunch
'
,
async
()
=>
{
page
=
await
program
.
navigateTo
(
CURRENT_PAGE_PATH
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
reLaunch
'
)
await
new
Promise
((
resolve
)
=>
{
setTimeout
(
resolve
,
1000
)
})
await
page
.
waitFor
(
500
)
page
=
await
program
.
navigateTo
(
CURRENT_PAGE_PATH
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
})
...
...
@@ -22,19 +27,17 @@ describe('navigator', () => {
it
(
'
navigateTo
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
navigateTo
'
)
await
new
Promise
((
resolve
)
=>
{
setTimeout
(
resolve
,
1000
)
})
await
page
.
waitFor
(
500
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
})
it
(
'
navigateTo error page
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
navigateToErrorPage
'
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
})
...
...
@@ -42,53 +45,70 @@ describe('navigator', () => {
it
(
'
navigateTo debounce
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
navigateToDebounce
'
)
await
new
Promise
((
resolve
)
=>
{
setTimeout
(
resolve
,
1000
)
})
await
page
.
waitFor
(
500
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
4
)
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
})
it
(
'
navigateTo relative path
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
navigateToRelativePath1
'
)
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
})
it
(
'
navigateTo relative path ./
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
navigateToRelativePath2
'
)
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
})
it
(
'
navigateTo relative path ../
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
navigateToRelativePath3
'
)
page
=
await
program
.
navigateBack
()
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
})
it
(
'
navigateBack
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
navigateBack
'
)
await
new
Promise
((
resolve
)
=>
{
setTimeout
(
resolve
,
1000
)
})
await
page
.
waitFor
(
500
)
page
=
await
program
.
navigateTo
(
CURRENT_PAGE_PATH
)
await
page
.
waitFor
(
500
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
})
it
(
'
navigateBackWithDelta1
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
navigateBackWithDelta1
'
)
await
page
.
waitFor
(
1000
)
page
=
await
program
.
currentPage
()
expect
(
`/
${
page
.
path
}
`
).
toBe
(
CURRENT_PAGE_PATH
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
})
it
(
'
navigateBackWithDelta100
'
,
async
()
=>
{
page
=
await
program
.
reLaunch
(
CURRENT_PAGE_PATH
)
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
navigateBackWithDelta100
'
)
await
page
.
waitFor
(
1000
)
page
=
await
program
.
currentPage
()
expect
(
`/
${
page
.
path
}
`
).
toBe
(
CURRENT_PAGE_PATH
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
})
...
...
@@ -96,11 +116,9 @@ describe('navigator', () => {
it
(
'
redirectTo
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
redirectTo
'
)
await
new
Promise
((
resolve
)
=>
{
setTimeout
(
resolve
,
1000
)
})
await
page
.
waitFor
(
500
)
page
=
await
program
.
redirectTo
(
CURRENT_PAGE_PATH
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
})
...
...
@@ -108,19 +126,10 @@ describe('navigator', () => {
it
(
'
switchTab
'
,
async
()
=>
{
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
0
)
await
page
.
callMethod
(
'
switchTab
'
)
await
new
Promise
((
resolve
)
=>
{
setTimeout
(
resolve
,
1000
)
})
await
page
.
waitFor
(
500
)
page
=
await
program
.
navigateTo
(
CURRENT_PAGE_PATH
)
await
page
.
waitFor
(
10
00
)
await
page
.
waitFor
(
5
00
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
2
)
})
it
(
'
reset lifecycle
'
,
async
()
=>
{
const
resetLifecycleNum
=
1100
await
page
.
callMethod
(
'
setLifeCycleNum
'
,
resetLifecycleNum
)
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
resetLifecycleNum
)
})
})
pages/API/navigator/navigator.uvue
浏览文件 @
23f789b1
...
...
@@ -240,6 +240,56 @@ export default {
},
})
},
navigateBackWithDelta1() {
uni.navigateTo({
url: '/pages/API/navigator/new-page/new-page-1',
success() {
uni.navigateBack({
delta: 1,
success(result) {
console.log('navigateBack success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(error) {
console.log('navigateBack fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete(result) {
console.log('navigateBack complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
},
})
},
navigateBackWithDelta100() {
uni.navigateTo({
url: '/pages/API/navigator/new-page/new-page-1',
success() {
uni.navigateBack({
delta: 100,
success(result) {
console.log('navigateBack success', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail(error) {
console.log('navigateBack fail', error.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete(result) {
console.log('navigateBack complete', result.errMsg)
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1)
},
})
},
})
},
redirectTo() {
uni.redirectTo({
url: '/pages/API/navigator/new-page/new-page-1?data=Hello',
...
...
pages/API/navigator/new-page/new-page-1.uvue
浏览文件 @
23f789b1
...
...
@@ -15,7 +15,6 @@ export default {
}
},
onLoad(options: OnLoadOptions) {
console.log('new-page2 onLoad', options)
if (options.has('data')) {
this.data = options.get('data')!
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录