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

refactor(getApp): 优化示例

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