提交 93ed0963 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test(list-view): 补充边界测试

上级 ae26661a
<template> <template>
<list-view> <list-view>
<slot></slot> <list-item>start</list-item>
<slot name="default"></slot>
<list-item>middle</list-item>
<slot name="second"></slot>
<list-item>end</list-item>
</list-view> </list-view>
</template> </template>
...@@ -13,38 +13,38 @@ describe('list-view-children-in-slot', () => { ...@@ -13,38 +13,38 @@ describe('list-view-children-in-slot', () => {
it('basic', async () => { it('basic', async () => {
let listItems = await page.$$('list-item') let listItems = await page.$$('list-item')
expect(listItems.length).toBe(3) expect(listItems.length).toBe(9)
let texts = await page.$$('.text-in-list-item') let texts = await page.$$('.text-in-list-item')
for(let i = 0;i<texts.length;i++){ for (let i = 0; i < texts.length; i++) {
expect(await texts[i].text()).toBe(`${i}`) expect(await texts[i].text()).toBe(`${i > (texts.length / 2 - 1)? i - texts.length / 2 : i}`)
} }
const addBtn = await page.$('#add-btn') const addBtn = await page.$('#add-btn')
await addBtn.tap() await addBtn.tap()
listItems = await page.$$('list-item') listItems = await page.$$('list-item')
expect(listItems.length).toBe(4) expect(listItems.length).toBe(11)
texts = await page.$$('.text-in-list-item') texts = await page.$$('.text-in-list-item')
for(let i = 0;i<texts.length;i++){ for (let i = 0; i < texts.length; i++) {
expect(await texts[i].text()).toBe(`${i}`) expect(await texts[i].text()).toBe(`${i > (texts.length / 2 - 1)? i - texts.length / 2 : i}`)
} }
const emptyBtn = await page.$('#empty-btn') const emptyBtn = await page.$('#empty-btn')
await emptyBtn.tap() await emptyBtn.tap()
listItems = await page.$$('list-item') listItems = await page.$$('list-item')
expect(listItems.length).toBe(0) expect(listItems.length).toBe(3)
await addBtn.tap() await addBtn.tap()
listItems = await page.$$('list-item') listItems = await page.$$('list-item')
expect(listItems.length).toBe(1) expect(listItems.length).toBe(5)
texts = await page.$$('.text-in-list-item') texts = await page.$$('.text-in-list-item')
for(let i = 0;i<texts.length;i++){ for (let i = 0; i < texts.length; i++) {
expect(await texts[i].text()).toBe(`${i}`) expect(await texts[i].text()).toBe(`0`)
} }
}) })
}) })
...@@ -6,9 +6,16 @@ ...@@ -6,9 +6,16 @@
<page-head title="getApp"></page-head> <page-head title="getApp"></page-head>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
<list-view-wrapper> <list-view-wrapper>
<template #default>
<list-item v-for="item in list" :key="item"> <list-item v-for="item in list" :key="item">
<text class="text-in-list-item">{{item}}</text> <text class="text-in-list-item">{{item}}</text>
</list-item> </list-item>
</template>
<template #second>
<list-item v-for="item in list" :key="item">
<text class="text-in-list-item">{{item}}</text>
</list-item>
</template>
</list-view-wrapper> </list-view-wrapper>
<button id="add-btn" class="uni-common-mt" @click="addItem">add item</button> <button id="add-btn" class="uni-common-mt" @click="addItem">add item</button>
<button id="empty-btn" class="uni-common-mt" @click="emptyList">empty list</button> <button id="empty-btn" class="uni-common-mt" @click="emptyList">empty list</button>
...@@ -30,10 +37,10 @@ ...@@ -30,10 +37,10 @@
} }
}, },
methods: { methods: {
addItem(){ addItem() {
this.list.push(this.list.length) this.list.push(this.list.length)
}, },
emptyList(){ emptyList() {
this.list = [] this.list = []
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册