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

refactor(getApp): 优化示例

上级 9316ff83
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)
})
})
......@@ -35,13 +35,14 @@
</template>
<text class="uni-common-mt">点击按钮调用 App.uvue methods</text>
<text class="uni-common-mt">increasetLifeCycleNum 方法</text>
<button class="uni-common-mt" @click="_increasetLifeCycleNum">
increase lifeCycleNum
<button class="uni-common-mt" @click="_increasetLifeCycleNum">
increase lifeCycleNum
</button>
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
<button class="uni-common-mt" @click="checkGetAndroidApplication">
check getAndroidApplication
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
<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() {
......@@ -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
}
},
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册