提交 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
...@@ -46,9 +48,9 @@ describe('getApp', () => { ...@@ -46,9 +48,9 @@ describe('getApp', () => {
const newLifeCycleNum = await page.data('lifeCycleNum') const newLifeCycleNum = await page.data('lifeCycleNum')
expect(newLifeCycleNum - oldLifeCycleNum).toBe(100) expect(newLifeCycleNum - oldLifeCycleNum).toBe(100)
await page.callMethod('setLifeCycleNum', oldLifeCycleNum) 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 @@ ...@@ -35,13 +35,14 @@
</template> </template>
<text class="uni-common-mt">点击按钮调用 App.uvue methods</text> <text class="uni-common-mt">点击按钮调用 App.uvue methods</text>
<text class="uni-common-mt">increasetLifeCycleNum 方法</text> <text class="uni-common-mt">increasetLifeCycleNum 方法</text>
<button class="uni-common-mt" @click="_increasetLifeCycleNum"> <button class="uni-common-mt" @click="_increasetLifeCycleNum">
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() {
...@@ -170,18 +172,11 @@ ...@@ -170,18 +172,11 @@
// 自动化测试 // 自动化测试
setLifeCycleNum(num : number) { setLifeCycleNum(num : number) {
setLifeCycleNum(num) setLifeCycleNum(num)
}, },
checkGetAndroidApplication() : boolean { getAndroidApplication() : boolean {
// #ifdef APP-ANDROID const app = getApp()
const res = true this.androidApplication = app.getAndroidApplication()
// #endif return this.androidApplication !== null
// #ifndef APP-ANDROID
const app = getApp()
const androidApplication = app.getAndroidApplication()
const res = 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.
先完成此消息的编辑!
想要评论请 注册