define-props.test.js 3.2 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3
const PAGE_PATH = '/pages/composition-api/basic/define-props/define-props'

describe('defineProps', () => {
4 5 6 7 8 9 10 11 12 13 14 15
  let page = null
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor('view')
  })
  it('basic', async () => {
    const arrayLiteralStr = await page.$('#array-literal-str')
    expect(await arrayLiteralStr.text()).toBe('str: default str')
    const arrayLiteralNum = await page.$('#array-literal-num')
    expect(await arrayLiteralNum.text()).toBe('num: 0')
    const arrayLiteralBool = await page.$('#array-literal-bool')
    expect(await arrayLiteralBool.text()).toBe('bool: false')
DCloud-WZF's avatar
DCloud-WZF 已提交
16 17
    const arrayLiteralArr = await page.$('#array-literal-arr')
    expect(await arrayLiteralArr.text()).toBe('arr: ["a","b","c"]')
18 19 20
    
    const arrayLiteralObj = await page.$('#array-literal-obj')
    if (process.env.uniTestPlatformInfo.startsWith('android')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
21
      expect(await arrayLiteralObj.text()).toBe('obj: {"arr":[1,2,3],"num":0,"str":"obj str"}')
22 23
    }
    if (process.env.uniTestPlatformInfo.startsWith('web')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
24
      expect(await arrayLiteralObj.text()).toBe(
25 26
        'obj: {"str": "obj str","num": 0,"arr": [1,2,3]}')
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
27

28 29 30 31 32 33 34 35 36 37
    const arrayLiteralFn = await page.$('#array-literal-fn')
    expect(await arrayLiteralFn.text()).toBe('fn: fn res')

    const objectLiteralStr = await page.$('#object-literal-str')
    expect(await objectLiteralStr.text()).toBe('str: default str')
    const objectLiteralNum = await page.$('#object-literal-num')
    expect(await objectLiteralNum.text()).toBe('num: 0')
    const objectLiteralBool = await page.$('#object-literal-bool')
    expect(await objectLiteralBool.text()).toBe('bool: false')
    const objectLiteralArr = await page.$('#object-literal-arr')
DCloud-WZF's avatar
DCloud-WZF 已提交
38
    expect(await objectLiteralArr.text()).toBe('arr: ["a","b","c"]')
39 40 41
    
    const objectLiteralObj = await page.$('#object-literal-obj')
    if (process.env.uniTestPlatformInfo.startsWith('android')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
42
      expect(await objectLiteralObj.text()).toBe('obj: {"a":1}')
43 44
    }
    if (process.env.uniTestPlatformInfo.startsWith('web')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
45 46
      expect(await objectLiteralObj.text()).toBe('obj: {"a": 1}')
    }
47 48 49
    
    const objectLiteralFn = await page.$('#object-literal-fn')
    expect(await objectLiteralFn.text()).toBe('fn: fn res')
DCloud-WZF's avatar
DCloud-WZF 已提交
50

51 52 53 54 55 56 57
    const typeStr = await page.$('#type-str')
    expect(await typeStr.text()).toBe('str: default str')
    const typeNum = await page.$('#type-num')
    expect(await typeNum.text()).toBe('num: 0')
    const typeBool = await page.$('#type-bool')
    expect(await typeBool.text()).toBe('bool: false')
    const typeArr = await page.$('#type-arr')
DCloud-WZF's avatar
DCloud-WZF 已提交
58
    expect(await typeArr.text()).toBe('arr: ["a","b","c"]')
59 60 61
    
    const typeObj = await page.$('#type-obj')
    if (process.env.uniTestPlatformInfo.startsWith('android')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
62
      expect(await typeObj.text()).toBe('obj: {"arr":[1,2,3],"num":0,"str":"obj str"}')
63 64
    }
    if (process.env.uniTestPlatformInfo.startsWith('web')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
65
      expect(await typeObj.text()).toBe('obj: {"str": "obj str","num": 0,"arr": [1,2,3]}')
66 67 68 69 70

    }
    const typeFn = await page.$('#type-fn')
    expect(await typeFn.text()).toBe('fn: fn res')
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
71
})