get-app.test.js 2.2 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3
const PAGE_PATH = '/pages/API/get-app/get-app'

describe('getApp', () => {
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  let page = null
  beforeAll(async () => {
    page = await program.navigateTo(PAGE_PATH)
    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'
DCloud-WZF's avatar
DCloud-WZF 已提交
19
    })
20 21
    expect(data.originGlobalData.arr).toEqual([])
    if (process.env.uniTestPlatformInfo.startsWith('android')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
22
      expect(data.originGlobalData.set).toEqual([])
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    } else {
      expect(data.originGlobalData.set).toEqual({})
    }
    expect(data.originGlobalData.map).toEqual({})
    expect(data.originGlobalDataFuncRes).toBe('globalData func')
    await page.callMethod('setGlobalData')
    data = await page.data()
    expect(data.newGlobalData.str).toBe('new globalData str')
    expect(data.newGlobalData.num).toBe(100)
    expect(data.newGlobalData.bool).toBe(true)
    expect(data.newGlobalData.obj).toEqual({
      bool: true,
      num: 200,
      str: 'new globalData obj str'
    })
    expect(data.newGlobalData.arr).toEqual([1, 2, 3])
    if (process.env.uniTestPlatformInfo.startsWith('android')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
40
      expect(data.newGlobalData.set).toEqual(['a', 'b', 'c'])
41 42 43 44
    } else {
      expect(data.originGlobalData.set).toEqual({})
    }
    if (process.env.uniTestPlatformInfo.startsWith('android')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
45 46 47 48 49
      expect(data.newGlobalData.map).toEqual({
        'a': 1,
        'b': 2,
        'c': 3
      })
50 51 52 53 54 55 56 57 58 59 60 61
    } else {
      expect(data.originGlobalData.map).toEqual({})
    }
    expect(data.newGlobalDataFuncRes).toBe('new globalData func')
  })
  it('method', async () => {
    const oldLifeCycleNum = await page.data('lifeCycleNum')
    await page.callMethod('_increasetLifeCycleNum')
    const newLifeCycleNum = await page.data('lifeCycleNum')
    expect(newLifeCycleNum - oldLifeCycleNum).toBe(100)
    await page.callMethod('setLifeCycleNum', oldLifeCycleNum)
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
62
})