From 5d624eac37e1ab31afd7fae845cb77f816a7c06d Mon Sep 17 00:00:00 2001
From: zhenyuWang <13641039885@163.com>
Date: Fri, 30 Jun 2023 21:46:39 +0800
Subject: [PATCH] feat: lifecycle
---
components/Lifecycle.uvue | 54 +++++++++++++++++++
pages.json | 9 +++-
.../component-lifecycle.test.js | 42 +++++++++++++++
.../component-lifecycle.uvue | 19 +++++++
pages/index.uvue | 9 +++-
pages/page-lifecycle/page-lifecycle.test.js | 32 +++++++----
6 files changed, 153 insertions(+), 12 deletions(-)
create mode 100644 components/Lifecycle.uvue
create mode 100644 pages/component-lifecycle/component-lifecycle.test.js
create mode 100644 pages/component-lifecycle/component-lifecycle.uvue
diff --git a/components/Lifecycle.uvue b/components/Lifecycle.uvue
new file mode 100644
index 0000000..7c4ee2b
--- /dev/null
+++ b/components/Lifecycle.uvue
@@ -0,0 +1,54 @@
+
+
+ {{title}}
+
+
+
+
diff --git a/pages.json b/pages.json
index a9b227b..ddb978c 100644
--- a/pages.json
+++ b/pages.json
@@ -52,12 +52,19 @@
"style": {
"navigationBarTitleText": "v-slot"
}
- },{
+ },
+ {
"path": "pages/page-lifecycle/page-lifecycle",
"style": {
"navigationBarTitleText": "page-lifecycle"
}
},
+ {
+ "path": "pages/component-lifecycle/component-lifecycle",
+ "style": {
+ "navigationBarTitleText": "component-lifecycle"
+ }
+ },
{
"path": "pages/component-instance/data/data",
"style": {
diff --git a/pages/component-lifecycle/component-lifecycle.test.js b/pages/component-lifecycle/component-lifecycle.test.js
new file mode 100644
index 0000000..340d3d4
--- /dev/null
+++ b/pages/component-lifecycle/component-lifecycle.test.js
@@ -0,0 +1,42 @@
+const PAGE_PATH = '/pages/component-lifecycle/component-lifecycle'
+const HOME_PATH = '/pages/index'
+
+describe('component-lifecycle', () => {
+ let page
+ let lifeCycleNum
+ beforeAll(async () => {
+ page = await program.reLaunch(HOME_PATH)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(1100)
+
+ const initLifecycleNum = 0
+ await page.callMethod('setLifeCycleNum', initLifecycleNum)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(initLifecycleNum)
+
+ page = await program.navigateTo(PAGE_PATH)
+ await page.waitFor(1000)
+ })
+ it('beforeCreate created beforeMount mounted', async () => {
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(4)
+ })
+ it('beforeUpdate updated', async () => {
+ const component = await page.$('.component-lifecycle')
+ await component.setData({
+ title: 'component for lifecycle test new title'
+ })
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(6)
+ })
+ it('beforeUnmount unmounted', async () => {
+ page = await program.navigateBack()
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(4)
+
+ const resetLifecycleNum = 1100
+ await page.callMethod('setLifeCycleNum', resetLifecycleNum)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(resetLifecycleNum)
+ })
+})
diff --git a/pages/component-lifecycle/component-lifecycle.uvue b/pages/component-lifecycle/component-lifecycle.uvue
new file mode 100644
index 0000000..14d0fe3
--- /dev/null
+++ b/pages/component-lifecycle/component-lifecycle.uvue
@@ -0,0 +1,19 @@
+
+
+ component lifecycle
+
+
+
+
+
diff --git a/pages/index.uvue b/pages/index.uvue
index a1f0f34..6dcd672 100644
--- a/pages/index.uvue
+++ b/pages/index.uvue
@@ -16,7 +16,7 @@