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

test(globalData): 支持 web 端测试

上级 f12b08cd
const PAGE_PATH = '/pages/API/get-app/get-app' const PAGE_PATH = '/pages/API/get-app/get-app'
describe('getApp', () => { describe('getApp', () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { let page = null
let page = null beforeAll(async () => {
beforeAll(async () => { page = await program.navigateTo(PAGE_PATH)
page = await program.navigateTo(PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') })
it('globalData', async () => {
await page.callMethod('getGlobalData')
let data = await page.data()
expect(data.originGlobalData.str).toBe('default globalData str')
expect(data.originGlobalData.num).toBe(0)
expect(data.originGlobalData.bool).toBe(false)
expect(data.originGlobalData.obj).toEqual({
bool: false,
num: 0,
str: 'default globalData obj str'
}) })
it('globalData', async () => { expect(data.originGlobalData.arr).toEqual([])
await page.callMethod('getGlobalData') if (process.env.uniTestPlatformInfo.startsWith('android')) {
let data = await page.data()
expect(data.originGlobalData.str).toBe('default globalData str')
expect(data.originGlobalData.num).toBe(0)
expect(data.originGlobalData.bool).toBe(false)
expect(data.originGlobalData.obj).toEqual({
bool: false,
num: 0,
str: 'default globalData obj str'
})
expect(data.originGlobalData.arr).toEqual([])
expect(data.originGlobalData.set).toEqual([]) expect(data.originGlobalData.set).toEqual([])
expect(data.originGlobalData.map).toEqual({}) } else {
expect(data.originGlobalDataFuncRes).toBe('globalData func') expect(data.originGlobalData.set).toEqual({})
await page.callMethod('setGlobalData') }
data = await page.data() expect(data.originGlobalData.map).toEqual({})
expect(data.newGlobalData.str).toBe('new globalData str') expect(data.originGlobalDataFuncRes).toBe('globalData func')
expect(data.newGlobalData.num).toBe(100) await page.callMethod('setGlobalData')
expect(data.newGlobalData.bool).toBe(true) data = await page.data()
expect(data.newGlobalData.obj).toEqual({ expect(data.newGlobalData.str).toBe('new globalData str')
bool: true, expect(data.newGlobalData.num).toBe(100)
num: 200, expect(data.newGlobalData.bool).toBe(true)
str: 'new globalData obj str' expect(data.newGlobalData.obj).toEqual({
}) bool: true,
expect(data.newGlobalData.arr).toEqual([1, 2, 3]) num: 200,
str: 'new globalData obj str'
})
expect(data.newGlobalData.arr).toEqual([1, 2, 3])
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(data.newGlobalData.set).toEqual(['a', 'b', 'c']) expect(data.newGlobalData.set).toEqual(['a', 'b', 'c'])
} else {
expect(data.originGlobalData.set).toEqual({})
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(data.newGlobalData.map).toEqual({ expect(data.newGlobalData.map).toEqual({
'a': 1, 'a': 1,
'b': 2, 'b': 2,
'c': 3 'c': 3
}) })
expect(data.newGlobalDataFuncRes).toBe('new globalData func') } else {
}) expect(data.originGlobalData.map).toEqual({})
it('method', async () => { }
const oldLifeCycleNum = await page.data('lifeCycleNum') expect(data.newGlobalDataFuncRes).toBe('new globalData func')
await page.callMethod('_increasetLifeCycleNum') })
const newLifeCycleNum = await page.data('lifeCycleNum') it('method', async () => {
expect(newLifeCycleNum - oldLifeCycleNum).toBe(100) const oldLifeCycleNum = await page.data('lifeCycleNum')
await page.callMethod('setLifeCycleNum', oldLifeCycleNum) await page.callMethod('_increasetLifeCycleNum')
}) const newLifeCycleNum = await page.data('lifeCycleNum')
} else { expect(newLifeCycleNum - oldLifeCycleNum).toBe(100)
// TODO: web 端暂不支持 await page.callMethod('setLifeCycleNum', oldLifeCycleNum)
it('web', async () => { })
expect(1).toBe(1)
})
}
}) })
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册