diff --git a/pages/API/get-app/get-app.test.js b/pages/API/get-app/get-app.test.js index ef9dffd05c73eca6f9fd9e853ccaf8bde7c2ae75..c8306e5250b969f81a0be62a90dda64f827011fe 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 2cdf2e5023e9b23824f72934e8113b908ea511dc..f1c2b08aa3ea7fbf2300ceb0516ed31bd5447c7d 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 } }, }