提交 21e5f843 编写于 作者: H hdx

getEnterOptionsSync: 简化示例,移除一些不必要的逻辑

上级 46afa092
const PAGE_PATH = '/pages/API/get-enter-options-sync/get-enter-options-sync' const PAGE_PATH = '/pages/API/get-enter-options-sync/get-enter-options-sync'
describe('getEnterOptionsSync', () => { describe('getEnterOptionsSync', () => {
it('getEnterOptionsSync', async () => {
const page = await program.navigateTo(PAGE_PATH)
await page.waitFor('view')
await page.callMethod('getEnterOptionsSync')
const data = await page.data()
expect(data.checked).toBe(true)
})
it('app onShow 和 getEnterOptionsSync 结果一致', async () => { it('app onShow 和 getEnterOptionsSync 结果一致', async () => {
const page = await program.navigateTo(PAGE_PATH) const page = await program.navigateTo(PAGE_PATH)
await page.waitFor('view') await page.waitFor('view')
const res = await page.callMethod('compareOnShowRes') const pageData = await page.data()
expect(pageData.testResult).toBe(true)
if (process.env.uniTestPlatformInfo.toLowerCase().startsWith('android')) {
// if android return
expect(true).toBe(true)
}
expect(res.appOnShow).toEqual(res.onShowOption)
}) })
}) })
<template> <template>
<page-head title="getEnterOptionsSync"></page-head> <page-head title="getEnterOptionsSync"></page-head>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
<button @click="getEnterOptionsSync">getEnterOptionsSync</button> <view class="uni-common-mt">
<view v-if="enterOptionsPath.length > 0" class="uni-common-mt"> <text>应用本次启动路径:</text>
<text>应用启动路径:</text> <text style="margin-top: 5px">{{ enterOptionsString }}</text>
<text style="margin-top: 5px">{{ EnterOptionsPath }}</text>
</view> </view>
</view> </view>
</template> </template>
<script lang="uts"> <script>
type OnShowReturn = {
appOnShow : OnShowOptions,
onShowOption : OnShowOptions
}
export default { export default {
data() { data() {
return { return {
checked: false, enterOptionsString: '',
homePagePath: 'pages/tabBar/component', testResult: false }
enterOptionsPath: '' } },
}, onReady() {
methods: { const app = getApp()
// 自动化测试 const appOnShow = app.globalData.onShowOption
compareOnShowRes() : OnShowReturn { const onShowOption = uni.getEnterOptionsSync()
this.enterOptionsString = JSON.stringify(onShowOption, null, 2)
// #ifdef APP-ANDROID this.testResult = (onShowOption.path == appOnShow.path && onShowOption.appScheme == appOnShow.appScheme && onShowOption.appLink == appOnShow.appLink)
const res : OnShowReturn = { }
appOnShow: {
path: ''
} as OnShowOptions,
onShowOption: {
path: ''
} as OnShowOptions
}
return res
// #endif
// #ifndef APP-ANDROID
const onShowOption = uni.getEnterOptionsSync();
const app = getApp()
const appOnShow = app.globalData.onShowOption as OnShowOptions
return {
appOnShow,
onShowOption
}
// #endif
},
getEnterOptionsSync() {
const enterOptions = uni.getEnterOptionsSync()
this.enterOptionsPath = enterOptions.path
if (enterOptions.path == this.homePagePath) {
this.checked = true
}
},
},
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册