globalProperties.test.js 2.3 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
const PAGE_PATH = '/pages/API/globalProperties/globalProperties'

describe('globalProperties', () => {
  if (process.env.uniTestPlatformInfo.startsWith('android')) {
    let page = null
    beforeAll(async () => {
      page = await program.navigateTo(PAGE_PATH)
      await page.waitFor(500)
    })
    it('globalProperties', async () => {
      let data = await page.data()
      expect(data.myGlobalProperties.str).toBe('default string')
      expect(data.myGlobalProperties.num).toBe(0)
      expect(data.myGlobalProperties.bool).toBe(false)
      expect(data.myGlobalProperties.obj).toEqual({
        bool: false,
        num: 0,
        str: 'default globalProperties obj string'
      })
      expect(data.myGlobalProperties.arr).toEqual([])
      expect(data.myGlobalProperties.set).toEqual([])
      expect(data.myGlobalProperties.map).toEqual({})
      expect(data.myGlobalProperties.reactiveObj).toEqual({
        str: 'default reactive string',
        num: 0,
        bool: false
      })
      expect(data.globalPropertiesFnRes).toBe('globalPropertiesStr: default string, globalPropertiesNum: 0')
      await page.callMethod('updateGlobalProperties')
      data = await page.data()
      expect(data.myGlobalProperties.str).toBe('new string')
      expect(data.myGlobalProperties.num).toBe(100)
      expect(data.myGlobalProperties.bool).toBe(true)
      expect(data.myGlobalProperties.obj).toEqual({
        bool: true,
        num: 100,
        str: 'new globalProperties obj string'
      })
      expect(data.myGlobalProperties.arr).toEqual([1, 2, 3])
      expect(data.myGlobalProperties.set).toEqual(['a', 'b', 'c'])
      expect(data.myGlobalProperties.map).toEqual({
        'a': 1,
        'b': 2,
        'c': 3
      })
      expect(data.myGlobalProperties.reactiveObj).toEqual({
        str: 'new reactive string',
        num: 200,
        bool: true
      })
      expect(data.globalPropertiesFnRes).toBe('globalPropertiesStr: new string, globalPropertiesNum: 100')
    })
    it('screenshot', async () => {
      const image = await program.screenshot({
        fullPage: true
      });
      expect(image).toMatchImageSnapshot();
    })
  } else {
    // TODO: web 端暂不支持
    it('web', async () => {
      expect(1).toBe(1)
    })
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
65
})