From 54314d039e0886f60ba4974c3a364dbc3f434bdf Mon Sep 17 00:00:00 2001
From: zhenyuWang <13641039885@163.com>
Date: Sat, 9 Nov 2024 10:41:11 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=20App.onError=20?=
=?UTF-8?q?=E6=8D=95=E8=8E=B7=E5=BC=82=E6=AD=A5=E5=BC=82=E5=B8=B8=E7=A4=BA?=
=?UTF-8?q?=E4=BE=8B=E5=8F=8A=E6=B5=8B=E8=AF=95=20issue:7116?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../throw-error/throw-error-composition.uvue | 10 +-
.../throw-error/throw-error-options.uvue | 54 +++++----
pages/error/throw-error/throw-error.test.js | 106 ++++++++++--------
3 files changed, 97 insertions(+), 73 deletions(-)
diff --git a/pages/error/throw-error/throw-error-composition.uvue b/pages/error/throw-error/throw-error-composition.uvue
index 090d286..89b5d04 100644
--- a/pages/error/throw-error/throw-error-composition.uvue
+++ b/pages/error/throw-error/throw-error-composition.uvue
@@ -1,18 +1,24 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pages/error/throw-error/throw-error.test.js b/pages/error/throw-error/throw-error.test.js
index 3d13236..20abea7 100644
--- a/pages/error/throw-error/throw-error.test.js
+++ b/pages/error/throw-error/throw-error.test.js
@@ -1,47 +1,59 @@
-const OPTIONS_PAGE_PATH = '/pages/error/throw-error/throw-error-options'
-const COMPOSITION_PAGE_PATH = '/pages/error/throw-error/throw-error-composition'
-const HOME_PAGE_PATH = '/pages/index/index'
-
-describe('throw error', () => {
- let page
- let lifeCycleNum
- const initLifecycle = async () => {
- page = await program.reLaunch(HOME_PAGE_PATH)
- await page.waitFor('view')
- await page.callMethod('setLifeCycleNum', 0)
- lifeCycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifeCycleNum).toBe(0)
- }
- const test = async (pagePath) => {
- await initLifecycle()
- page = await program.reLaunch(pagePath)
- await page.waitFor('view')
- expect(page.path).toBe(pagePath.substring(1))
-
- lifeCycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifeCycleNum).toBe(100)
-
- const triggerErrorBtn = await page.$('#trigger-error')
- await triggerErrorBtn.tap()
-
- lifeCycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifeCycleNum).toBe(200)
-
- page = await program.navigateTo(HOME_PAGE_PATH)
- await page.waitFor('view')
- expect(page.path).toBe(HOME_PAGE_PATH.substring(1))
- }
- it('onError options API', async () => {
- await test(OPTIONS_PAGE_PATH)
- })
- it('onError composition API', async () => {
- await test(COMPOSITION_PAGE_PATH)
- })
-
- afterAll(async () => {
- const resetLifecycleNum = 1110
- await page.callMethod('setLifeCycleNum', resetLifecycleNum)
- lifeCycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifeCycleNum).toBe(resetLifecycleNum)
- })
-})
+const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
+const isAndroid = platformInfo.includes('android')
+const isIos = platformInfo.includes('ios')
+const OPTIONS_PAGE_PATH = '/pages/error/throw-error/throw-error-options'
+const COMPOSITION_PAGE_PATH = '/pages/error/throw-error/throw-error-composition'
+const HOME_PAGE_PATH = '/pages/index/index'
+
+describe('throw error', () => {
+ let page
+ let lifeCycleNum
+ const initLifecycle = async () => {
+ page = await program.reLaunch(HOME_PAGE_PATH)
+ await page.waitFor('view')
+ await page.callMethod('setLifeCycleNum', 0)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(0)
+ }
+ const test = async (pagePath) => {
+ await initLifecycle()
+ page = await program.reLaunch(pagePath)
+ await page.waitFor('view')
+ expect(page.path).toBe(pagePath.substring(1))
+
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(100)
+
+ const triggerErrorBtn = await page.$('#trigger-error')
+ await triggerErrorBtn.tap()
+
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(200)
+
+ if (isAndroid || isIos) {
+ const triggerTimeoutErrorBtn = await page.$('#trigger-timeout-error')
+ await triggerTimeoutErrorBtn.tap()
+ await page.waitFor(500)
+
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(300)
+ }
+
+ page = await program.navigateTo(HOME_PAGE_PATH)
+ await page.waitFor('view')
+ expect(page.path).toBe(HOME_PAGE_PATH.substring(1))
+ }
+ it('onError options API', async () => {
+ await test(OPTIONS_PAGE_PATH)
+ })
+ it('onError composition API', async () => {
+ await test(COMPOSITION_PAGE_PATH)
+ })
+
+ afterAll(async () => {
+ const resetLifecycleNum = 1110
+ await page.callMethod('setLifeCycleNum', resetLifecycleNum)
+ lifeCycleNum = await page.callMethod('getLifeCycleNum')
+ expect(lifeCycleNum).toBe(resetLifecycleNum)
+ })
+})
\ No newline at end of file
--
GitLab