From 5bb37961785a68712505a0730c77ebe9e9134aa8 Mon Sep 17 00:00:00 2001
From: zhenyuWang <13641039885@163.com>
Date: Thu, 19 Sep 2024 17:09:50 +0800
Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=20keepAlive=20?=
=?UTF-8?q?=E7=BB=84=E4=BB=B6=E9=9D=9E=E9=A2=84=E6=9C=9F=E8=A7=A6=E5=8F=91?=
=?UTF-8?q?=20update=20=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E5=90=8E?=
=?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B5=8B=E8=AF=95=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pages/lifecycle/component/component-composition.test.js | 4 ++--
pages/lifecycle/component/component-composition.uvue | 9 ++++++++-
pages/lifecycle/component/component-options.test.js | 9 +++------
pages/lifecycle/component/component-options.uvue | 8 +++++++-
4 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/pages/lifecycle/component/component-composition.test.js b/pages/lifecycle/component/component-composition.test.js
index 586be2a..d6059e2 100644
--- a/pages/lifecycle/component/component-composition.test.js
+++ b/pages/lifecycle/component/component-composition.test.js
@@ -40,8 +40,8 @@ describe('component-lifecycle', () => {
await toggleAliveComponentBtn.tap()
lifeCycleNum = await page.callMethod('pageGetLifeCycleNum')
- // TODO: android 端 keep-alive 组件切换时,不触发 activated, 会触发 beforeUpdate updated
- expect(lifeCycleNum).toBe(isAndroid ? 114 : 113)
+ // TODO: android 端 组合式 API 不触发 activated
+ expect(lifeCycleNum).toBe(isAndroid ? 112 : 113)
await page.callMethod('pageSetLifeCycleNum', 0)
})
it('onBeforeUpdate onUpdated', async () => {
diff --git a/pages/lifecycle/component/component-composition.uvue b/pages/lifecycle/component/component-composition.uvue
index 5dfd68d..416172c 100644
--- a/pages/lifecycle/component/component-composition.uvue
+++ b/pages/lifecycle/component/component-composition.uvue
@@ -7,8 +7,9 @@
-
+
+
@@ -61,6 +62,12 @@
// 自动化测试
const getIsScrolled = () : boolean => {
return isScrolled.value
+ }
+
+ const navigateToHome = () => {
+ uni.navigateTo({
+ url: '/pages/index/index'
+ })
}
defineExpose({
diff --git a/pages/lifecycle/component/component-options.test.js b/pages/lifecycle/component/component-options.test.js
index 00d5f2f..cc8f618 100644
--- a/pages/lifecycle/component/component-options.test.js
+++ b/pages/lifecycle/component/component-options.test.js
@@ -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
diff --git a/pages/lifecycle/component/component-options.uvue b/pages/lifecycle/component/component-options.uvue
index 7673f33..c5b9737 100644
--- a/pages/lifecycle/component/component-options.uvue
+++ b/pages/lifecycle/component/component-options.uvue
@@ -4,7 +4,8 @@
-
+
+
@@ -26,6 +27,11 @@ export default {
},
toggleAliveComponent(){
this.aliveComponent = this.aliveComponent == null ? ChildComponent : null
+ },
+ navigateToHome() {
+ uni.navigateTo({
+ url: '/pages/index/index'
+ })
}
},
}
--
GitLab