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

3 4
describe('defineProps', () => {
	const isSafari = process.env.uniTestPlatformInfo.indexOf('safari') > -1
5 6 7 8 9 10 11 12 13 14 15 16
  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 已提交
17
    const arrayLiteralArr = await page.$('#array-literal-arr')
18
    expect(await arrayLiteralArr.text()).toBe(isSafari ? 'arr: [ "a", "b", "c"]' : 'arr: ["a","b","c"]')
19 20 21
    
    const arrayLiteralObj = await page.$('#array-literal-obj')
    if (process.env.uniTestPlatformInfo.startsWith('android')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
22
      expect(await arrayLiteralObj.text()).toBe('obj: {"arr":[1,2,3],"num":0,"str":"obj str"}')
23 24
    }
    if (process.env.uniTestPlatformInfo.startsWith('web')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
25
      expect(await arrayLiteralObj.text()).toBe(
26
       isSafari ? 'obj: { "str": "obj str", "num": 0, "arr": [ 1, 2, 3 ]}' : 'obj: {"str": "obj str","num": 0,"arr": [1,2,3]}')
27
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
28

29 30 31 32 33 34 35 36 37 38
    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')
39
    expect(await objectLiteralArr.text()).toBe(isSafari ? 'arr: [ "a", "b", "c"]' : 'arr: ["a","b","c"]')
40 41 42
    
    const objectLiteralObj = await page.$('#object-literal-obj')
    if (process.env.uniTestPlatformInfo.startsWith('android')) {
DCloud-WZF's avatar
DCloud-WZF 已提交
43
      expect(await objectLiteralObj.text()).toBe('obj: {"a":1}')
44 45
    }
    if (process.env.uniTestPlatformInfo.startsWith('web')) {
46
      expect(await objectLiteralObj.text()).toBe(isSafari ? 'obj: { "a": 1}' : 'obj: {"a": 1}')
DCloud-WZF's avatar
DCloud-WZF 已提交
47
    }
48 49 50
    
    const objectLiteralFn = await page.$('#object-literal-fn')
    expect(await objectLiteralFn.text()).toBe('fn: fn res')
DCloud-WZF's avatar
DCloud-WZF 已提交
51

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

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