Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
5bb37961
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
348
Star
2
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello-uvue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
5bb37961
编写于
9月 19, 2024
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: 修复 keepAlive 组件非预期触发 update 生命周期后更新测试例
上级
af1c47ed
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
20 addition
and
10 deletion
+20
-10
pages/lifecycle/component/component-composition.test.js
pages/lifecycle/component/component-composition.test.js
+2
-2
pages/lifecycle/component/component-composition.uvue
pages/lifecycle/component/component-composition.uvue
+8
-1
pages/lifecycle/component/component-options.test.js
pages/lifecycle/component/component-options.test.js
+3
-6
pages/lifecycle/component/component-options.uvue
pages/lifecycle/component/component-options.uvue
+7
-1
未找到文件。
pages/lifecycle/component/component-composition.test.js
浏览文件 @
5bb37961
...
...
@@ -40,8 +40,8 @@ describe('component-lifecycle', () => {
await
toggleAliveComponentBtn
.
tap
()
lifeCycleNum
=
await
page
.
callMethod
(
'
pageGetLifeCycleNum
'
)
// TODO: android 端
keep-alive 组件切换时,不触发 activated, 会触发 beforeUpdate upd
ated
expect
(
lifeCycleNum
).
toBe
(
isAndroid
?
11
4
:
113
)
// TODO: android 端
组合式 API 不触发 activ
ated
expect
(
lifeCycleNum
).
toBe
(
isAndroid
?
11
2
:
113
)
await
page
.
callMethod
(
'
pageSetLifeCycleNum
'
,
0
)
})
it
(
'
onBeforeUpdate onUpdated
'
,
async
()
=>
{
...
...
pages/lifecycle/component/component-composition.uvue
浏览文件 @
5bb37961
...
...
@@ -7,8 +7,9 @@
<keep-alive>
<component :is="aliveComponent" @updateIsScroll="updateIsScroll" />
</keep-alive>
<button class="mt-10" @click="scrollToBottom">scrollToBottom</button>
<button class="mt-10" @click="scrollToBottom">scrollToBottom</button>
<button id="toggle-alive-component-btn" class="mt-10" @click="toggleAliveComponent">toggle alive component</button>
<button class="mt-10" @click="navigateToHome">navigateTo home</button>
</view>
<!-- #ifdef APP -->
</scroll-view>
...
...
@@ -61,6 +62,12 @@
// 自动化测试
const getIsScrolled = () : boolean => {
return isScrolled.value
}
const navigateToHome = () => {
uni.navigateTo({
url: '/pages/index/index'
})
}
defineExpose({
...
...
pages/lifecycle/component/component-options.test.js
浏览文件 @
5bb37961
...
...
@@ -4,8 +4,6 @@ const HOME_PATH = '/pages/index/index'
describe
(
'
component-lifecycle
'
,
()
=>
{
let
page
let
lifeCycleNum
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLocaleLowerCase
()
const
isAndroid
=
platformInfo
.
includes
(
'
android
'
)
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
HOME_PATH
)
await
page
.
waitFor
(
700
)
...
...
@@ -33,20 +31,19 @@ describe('component-lifecycle', () => {
await
toggleAliveComponentBtn
.
tap
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
4
)
// TODO: android 端 keep-alive 组件切换时,不仅触发 activated, 之前还会触发 beforeUpdate updated
await
toggleAliveComponentBtn
.
tap
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
isAndroid
?
7
:
5
)
expect
(
lifeCycleNum
).
toBe
(
5
)
})
it
(
'
beforeUpdate updated
'
,
async
()
=>
{
const
updateTitleBtn
=
await
page
.
$
(
'
.component-lifecycle-btn
'
)
await
updateTitleBtn
.
tap
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
isAndroid
?
9
:
7
)
expect
(
lifeCycleNum
).
toBe
(
7
)
})
it
(
'
deactivated beforeUnmount unmounted
'
,
async
()
=>
{
page
=
await
program
.
navigateBack
()
lifeCycleNum
=
await
page
.
callMethod
(
'
getLifeCycleNum
'
)
expect
(
lifeCycleNum
).
toBe
(
isAndroid
?
6
:
4
)
expect
(
lifeCycleNum
).
toBe
(
4
)
})
})
\ No newline at end of file
pages/lifecycle/component/component-options.uvue
浏览文件 @
5bb37961
...
...
@@ -4,7 +4,8 @@
<keep-alive>
<component :is="aliveComponent" />
</keep-alive>
<button id="toggle-alive-component-btn" class="mt-10" @click="toggleAliveComponent">toggle alive component</button>
<button id="toggle-alive-component-btn" class="mt-10" @click="toggleAliveComponent">toggle alive component</button>
<button class="mt-10" @click="navigateToHome">navigateTo home</button>
</view>
</template>
...
...
@@ -26,6 +27,11 @@ export default {
},
toggleAliveComponent(){
this.aliveComponent = this.aliveComponent == null ? ChildComponent : null
},
navigateToHome() {
uni.navigateTo({
url: '/pages/index/index'
})
}
},
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录