From c3334609e12dfee8ae108c109399f670f8a7f52c Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Wed, 16 Oct 2024 09:18:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor(getApp):=20=E4=BC=98=E5=8C=96=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/API/get-app/get-app.test.js | 12 +++++++----- pages/API/get-app/get-app.uvue | 29 ++++++++++++----------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/pages/API/get-app/get-app.test.js b/pages/API/get-app/get-app.test.js index ef9dffd0..c8306e52 100644 --- a/pages/API/get-app/get-app.test.js +++ b/pages/API/get-app/get-app.test.js @@ -1,4 +1,6 @@ const PAGE_PATH = '/pages/API/get-app/get-app' +const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() +const isAndroid = platformInfo.startsWith('android') describe('getApp', () => { let page = null @@ -46,9 +48,9 @@ describe('getApp', () => { const newLifeCycleNum = await page.data('lifeCycleNum') expect(newLifeCycleNum - oldLifeCycleNum).toBe(100) await page.callMethod('setLifeCycleNum', oldLifeCycleNum) - }) - it('getAndroidApplication', async () => { - const res = await page.callMethod('checkGetAndroidApplication') - expect(res).toBe(true) }) -}) + it('getAndroidApplication', async () => { + const res = await page.callMethod('getAndroidApplication') + expect(res).toBe(isAndroid) + }) +}) diff --git a/pages/API/get-app/get-app.uvue b/pages/API/get-app/get-app.uvue index 2cdf2e50..f1c2b08a 100644 --- a/pages/API/get-app/get-app.uvue +++ b/pages/API/get-app/get-app.uvue @@ -35,13 +35,14 @@ 点击按钮调用 App.uvue methods increasetLifeCycleNum 方法 - - lifeCycleNum: {{ lifeCycleNum }} - + androidApplication is null: {{ androidApplication == null }} @@ -100,6 +101,7 @@ } as MyGlobalData, newGlobalDataFuncRes: '', lifeCycleNum: 0, + androidApplication: null as any | null } }, onReady() { @@ -170,18 +172,11 @@ // 自动化测试 setLifeCycleNum(num : number) { setLifeCycleNum(num) - }, - checkGetAndroidApplication() : boolean { - // #ifdef APP-ANDROID - const res = true - // #endif - // #ifndef APP-ANDROID - const app = getApp() - const androidApplication = app.getAndroidApplication() - const res = androidApplication == null - // #endif - console.log('check getAndroidApplication', res) - return res + }, + getAndroidApplication() : boolean { + const app = getApp() + this.androidApplication = app.getAndroidApplication() + return this.androidApplication !== null } }, } -- GitLab