提交 c3334609 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

refactor(getApp): 优化示例

上级 9316ff83
const PAGE_PATH = '/pages/API/get-app/get-app' const PAGE_PATH = '/pages/API/get-app/get-app'
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
describe('getApp', () => { describe('getApp', () => {
let page = null let page = null
...@@ -48,7 +50,7 @@ describe('getApp', () => { ...@@ -48,7 +50,7 @@ describe('getApp', () => {
await page.callMethod('setLifeCycleNum', oldLifeCycleNum) await page.callMethod('setLifeCycleNum', oldLifeCycleNum)
}) })
it('getAndroidApplication', async () => { it('getAndroidApplication', async () => {
const res = await page.callMethod('checkGetAndroidApplication') const res = await page.callMethod('getAndroidApplication')
expect(res).toBe(true) expect(res).toBe(isAndroid)
}) })
}) })
...@@ -39,9 +39,10 @@ ...@@ -39,9 +39,10 @@
increase lifeCycleNum increase lifeCycleNum
</button> </button>
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text> <text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
<button class="uni-common-mt" @click="checkGetAndroidApplication"> <button class="uni-common-mt" @click="getAndroidApplication">
check getAndroidApplication getAndroidApplication
</button> </button>
<text class="uni-common-mt">androidApplication is null: {{ androidApplication == null }}</text>
</view> </view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
...@@ -100,6 +101,7 @@ ...@@ -100,6 +101,7 @@
} as MyGlobalData, } as MyGlobalData,
newGlobalDataFuncRes: '', newGlobalDataFuncRes: '',
lifeCycleNum: 0, lifeCycleNum: 0,
androidApplication: null as any | null
} }
}, },
onReady() { onReady() {
...@@ -171,17 +173,10 @@ ...@@ -171,17 +173,10 @@
setLifeCycleNum(num : number) { setLifeCycleNum(num : number) {
setLifeCycleNum(num) setLifeCycleNum(num)
}, },
checkGetAndroidApplication() : boolean { getAndroidApplication() : boolean {
// #ifdef APP-ANDROID
const res = true
// #endif
// #ifndef APP-ANDROID
const app = getApp() const app = getApp()
const androidApplication = app.getAndroidApplication() this.androidApplication = app.getAndroidApplication()
const res = androidApplication == null return this.androidApplication !== null
// #endif
console.log('check getAndroidApplication', res)
return res
} }
}, },
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册