v-for.test.js 2.6 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2
const OPTIONS_PAGE_PATH = '/pages/directive/v-for/v-for-options'
const COMPOSITION_PAGE_PATH = '/pages/directive/v-for/v-for-composition'
H
init.  
hdx 已提交
3 4 5

describe('v-for', () => {
  let page
DCloud-WZF's avatar
DCloud-WZF 已提交
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
  
  const test = async (page) => {
    // v-for number
    const num1 = await page.$('#number-1')
    expect(await num1.text()).toBe('1')
    const num2 = await page.$('#number-2')
    expect(await num2.text()).toBe('2')
    const num3 = await page.$('#number-3')
    expect(await num3.text()).toBe('3')

    // v-for object
    const value1 = await page.$('#value1')
    expect(await value1.text()).toBe('value1')
    const value2 = await page.$('#value2')
    expect(await value2.text()).toBe('value2')
    const value3 = await page.$('#value3')
    expect(await value3.text()).toBe('value3')
    
    const vIf1Count = await page.$('#v-if-1-count')
    expect(await vIf1Count.text()).toBe('0')
    
    await vIf1Count.tap()
    expect(await vIf1Count.text()).toBe('1')
    
    const vShow1Count = await page.$('#v-show-1-count')
    expect(await vShow1Count.text()).toBe('1')
    
    await vShow1Count.tap()
    expect(await vShow1Count.text()).toBe('2')
    
36 37 38 39 40 41 42 43 44 45 46 47 48
    const mapValue1 = await page.$('#map-key-1')
    expect(await mapValue1.text()).toBe('map value 1')
    const mapValue2 = await page.$('#map-key-2')
    expect(await mapValue2.text()).toBe('map value 2')
    const mapValue3 = await page.$('#map-key-3')
    expect(await mapValue3.text()).toBe('map value 3')
    
    const setValue1 = await page.$('#set-value-1')
    expect(await setValue1.text()).toBe('set value 1')
    const setValue2 = await page.$('#set-value-2')
    expect(await setValue2.text()).toBe('set value 2')
    const setValue3 = await page.$('#set-value-3')
    expect(await setValue3.text()).toBe('set value 3')
H
hdx 已提交
49 50 51 52 53 54 55 56 57 58 59

    // v-for UTSJSONObject
    for (let i = 1; i <= 3; i++) {
      /// key
      let utsKey = await page.$('#utsKey' + i)
      expect(await utsKey.text()).toBe('utsKey' + i)
      /// value
      let utsValue = await page.$('#UTSJSONObject-value' + i)
      expect(await utsValue.text()).toBe('UTSJSONObject-value' + i)
    }

DCloud-WZF's avatar
DCloud-WZF 已提交
60
    await page.waitFor(500)
H
hdx 已提交
61

DCloud-WZF's avatar
DCloud-WZF 已提交
62 63 64 65 66 67 68 69
    const image = await program.screenshot({
			fullPage: true
		});
		expect(image).toSaveImageSnapshot();
  }
  it('v-for options API', async () => {
    page = await program.reLaunch(OPTIONS_PAGE_PATH)
    await page.waitFor('view')
H
hdx 已提交
70
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
71 72
    
    await test(page)
H
init.  
hdx 已提交
73
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
74 75 76 77 78 79 80
  
  it('v-for composition API', async () => {
    page = await program.reLaunch(COMPOSITION_PAGE_PATH)
    await page.waitFor('view')
    await page.waitFor(500)
    
    await test(page)
H
init.  
hdx 已提交
81 82
  })
})