props.test.js 2.4 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2
const OPTIONS_PAGE_PATH = '/pages/component-instance/props/props-options'
const COMPOSITION_PAGE_PATH = '/pages/component-instance/props/props-composition'
3

4 5 6
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.includes('android')

DCloud-WZF's avatar
DCloud-WZF 已提交
7
describe('props', () => {
8
  let page
DCloud-WZF's avatar
DCloud-WZF 已提交
9
  const test = async (page) => {
10
    const arrayLiteralStr = await page.$('#array-literal-str')
DCloud-WZF's avatar
DCloud-WZF 已提交
11
    expect(await arrayLiteralStr.text()).toBe('str')
12

13
    const arrayLiteralNum = await page.$('#array-literal-num')
DCloud-WZF's avatar
DCloud-WZF 已提交
14
    expect(await arrayLiteralNum.text()).toBe('10')
15

16 17
    const arrayLiteralBool = await page.$('#array-literal-bool')
    expect(await arrayLiteralBool.text()).toBe('true')
18

19
    const arrayLiteralObj = await page.$('#array-literal-obj')
DCloud-WZF's avatar
DCloud-WZF 已提交
20
    expect(await arrayLiteralObj.text()).toBe('{"age":18}')
21

22
    const arrayLiteralArr = await page.$('#array-literal-arr')
DCloud-WZF's avatar
DCloud-WZF 已提交
23
    expect(await arrayLiteralArr.text()).toBe('["a","b","c"]')
24

DCloud-WZF's avatar
DCloud-WZF 已提交
25 26
    const objectTypeStr = await page.$('#object-type-str')
    expect(await objectTypeStr.text()).toBe('str')
27

DCloud-WZF's avatar
DCloud-WZF 已提交
28 29
    const objectTypeNum = await page.$('#object-type-num')
    expect(await objectTypeNum.text()).toBe('10')
30

DCloud-WZF's avatar
DCloud-WZF 已提交
31 32
    const objectTypeBool = await page.$('#object-type-bool')
    expect(await objectTypeBool.text()).toBe('true')
33

DCloud-WZF's avatar
DCloud-WZF 已提交
34 35
    const objectTypeObj = await page.$('#object-type-obj')
    expect(await objectTypeObj.text()).toBe('{"age":18}')
36

DCloud-WZF's avatar
DCloud-WZF 已提交
37 38
    const objectTypeArr = await page.$('#object-type-arr')
    expect(await objectTypeArr.text()).toBe('["a","b","c"]')
39

DCloud-WZF's avatar
DCloud-WZF 已提交
40 41
    const sameNamePropDefaultValueArr = await page.$('#same-name-prop-default-value-arr')
    expect(await sameNamePropDefaultValueArr.text()).toBe('[1,2,3]')
42 43 44 45 46

    const propMsg = await page.$('#prop-msg')
    expect(await propMsg.text()).toBe('hello')
    const propLabels = await page.$('#prop-labels')
    expect(await propLabels.text()).toBe('["a","b"]')
47 48 49

    const referenceTypeList = await page.$('#reference-type-list')
    expect(await referenceTypeList.text()).toBe(isAndroid ? '[1,2,3]' : '["a","b","c"]')
DCloud-WZF's avatar
DCloud-WZF 已提交
50
  }
51

DCloud-WZF's avatar
DCloud-WZF 已提交
52 53
  it('props 选项式 API', async () => {
    page = await program.reLaunch(OPTIONS_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
54
    await page.waitFor('view')
55

DCloud-WZF's avatar
DCloud-WZF 已提交
56 57
    await test(page)
  });
58

DCloud-WZF's avatar
DCloud-WZF 已提交
59 60
  it('props 组合式 API', async () => {
    page = await program.reLaunch(COMPOSITION_PAGE_PATH)
DCloud-WZF's avatar
DCloud-WZF 已提交
61
    await page.waitFor('view')
62

DCloud-WZF's avatar
DCloud-WZF 已提交
63
    await test(page)
64 65
  })
})