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

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

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

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

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