globalProperties.test.js 1.8 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
const PAGE_PATH = '/pages/API/globalProperties/globalProperties'

describe('globalProperties', () => {
  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();
  })
})