提交 521ba91e 编写于 作者: 辛宝Otto's avatar 辛宝Otto 🥊

feat: 添加 onLaunch/onShow 相关测试

上级 4a566e93
...@@ -20,9 +20,17 @@ ...@@ -20,9 +20,17 @@
myMap: new Map<string, any>(), myMap: new Map<string, any>(),
func: () : string => { func: () : string => {
return 'globalData func' return 'globalData func'
}
}, },
onLaunch: function () { launchOptions: {
path: '',
} as OnLaunchOptions,
onShowOption: {
path: ''
} as OnShowOptions
},
onLaunch: function (res : OnLaunchOptions) {
this.globalData.launchOptions = res
// 自动化测试 // 自动化测试
setLifeCycleNum(state.lifeCycleNum + 1000) setLifeCycleNum(state.lifeCycleNum + 1000)
console.log('App Launch') console.log('App Launch')
...@@ -38,7 +46,9 @@ ...@@ -38,7 +46,9 @@
// entryTypes: ['render', 'navigation'], // entryTypes: ['render', 'navigation'],
// } as PerformanceObserverOptions) // } as PerformanceObserverOptions)
}, },
onShow: function () { onShow: function (res : OnShowOptions) {
this.globalData.onShowOption = res
// 自动化测试 // 自动化测试
setLifeCycleNum(state.lifeCycleNum + 100) setLifeCycleNum(state.lifeCycleNum + 100)
console.log('App Show') console.log('App Show')
...@@ -83,12 +93,15 @@ ...@@ -83,12 +93,15 @@
<style> <style>
/*每个页面公共css */ /*每个页面公共css */
@import "./common/uni.css"; @import "./common/uni.css";
/* #ifdef WEB */ /* #ifdef WEB */
.uni-top-window uni-tabbar .uni-tabbar { .uni-top-window uni-tabbar .uni-tabbar {
background-color: #fff !important; background-color: #fff !important;
} }
.uni-app--showleftwindow .uni-page-head-btn { .uni-app--showleftwindow .uni-page-head-btn {
display: none !important; display: none !important;
} }
/* #endif */ /* #endif */
</style> </style>
...@@ -8,4 +8,16 @@ describe('getLaunchOptionsSync', () => { ...@@ -8,4 +8,16 @@ describe('getLaunchOptionsSync', () => {
const data = await page.data() const data = await page.data()
expect(data.checked).toBe(true) expect(data.checked).toBe(true)
}) })
it('app onLaunch 和 getLaunchOptionsSync 结果一致', async () => {
const page = await program.navigateTo(PAGE_PATH)
await page.waitFor('view')
const res = await page.callMethod('compareOnLaunchRes')
expect(res.appOnLaunch).toEqual(res.launchOptions)
})
it('app onShow 和 getEnterOptionsSync 结果一致', async () => {
const page = await program.navigateTo(PAGE_PATH)
await page.waitFor('view')
const res = await page.callMethod('compareOnShowRes')
expect(res.appOnShow).toEqual(res.onShowOption)
})
}) })
...@@ -20,6 +20,27 @@ export default { ...@@ -20,6 +20,27 @@ export default {
} }
}, },
methods: { methods: {
// 自动化测试
compareOnLaunchRes() {
const launchOptions = uni.getLaunchOptionsSync();
const app = getApp()
const appOnLaunch = app.globalData.launchOptions;
return {
appOnLaunch,
launchOptions
}
},
compareOnShowRes() {
const onShowOption = uni.getEnterOptionsSync();
const app = getApp()
const appOnShow = app.globalData.onShowOption
return {
appOnShow,
onShowOption
}
},
getLaunchOptionsSync() { getLaunchOptionsSync() {
const launchOptions = uni.getLaunchOptionsSync() const launchOptions = uni.getLaunchOptionsSync()
this.launchOptionsPath = launchOptions.path this.launchOptionsPath = launchOptions.path
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册