v-for.test.js 1.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 36 37 38 39 40 41 42 43 44 45
  
  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')
    
    await page.waitFor(500)
    
    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 已提交
46
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
47 48
    
    await test(page)
H
init.  
hdx 已提交
49
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
50 51 52 53 54 55 56
  
  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 已提交
57 58
  })
})