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

test(KeepAlive): 补充生命周期测试

上级 f4154337
......@@ -2,6 +2,8 @@
<view>
<text class="counter-text">count: {{ count }}</text>
<text class="uni-common-mt counter-btn" @click="increment"></text>
<text class="uni-common-mt" id="activated-num">activated num: {{ activatedNum }}</text>
<text class="uni-common-mt" id="deactivated-num">deactivated num: {{ deactivatedNum }}</text>
</view>
</template>
......@@ -10,9 +12,13 @@
name: 'Counter',
data() {
return {
count: 0
count: 0,
activatedNum: 0,
deactivatedNum: 0,
}
},
activated() { this.activatedNum++ },
deactivated() { this.deactivatedNum++ },
methods: {
increment() {
this.count++
......
......@@ -19,6 +19,11 @@ describe('keep-alive', () => {
const showCounterBtn = await page.$('.show-counter')
await showCounterBtn.tap()
const activatedNum = await page.$('#activated-num')
expect(await activatedNum.text()).toBe('activated num: 1')
const deactivatedNum = await page.$('#deactivated-num')
expect(await deactivatedNum.text()).toBe('deactivated num: 0')
const counterBtns = await page.$$('.counter-btn')
for (let i = 0; i < counterBtns.length; i++) {
await counterBtns[i].tap()
......@@ -38,6 +43,9 @@ describe('keep-alive', () => {
await showCounterBtn.tap()
expect(await activatedNum.text()).toBe('activated num: 2')
expect(await deactivatedNum.text()).toBe('deactivated num: 1')
let counterTexts = await page.$$('.counter-text')
for (let i = 0; i < counterTexts.length; i++) {
expect(await counterTexts[i].text()).toBe('count: 1')
......@@ -58,6 +66,9 @@ describe('keep-alive', () => {
await showCounterBtn.tap()
expect(await activatedNum.text()).toBe('activated num: 3')
expect(await deactivatedNum.text()).toBe('deactivated num: 2')
counterTexts = await page.$$('.counter-text')
for (let i = 0; i < counterTexts.length; i++) {
expect(await counterTexts[i].text()).toBe('count: 1')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册