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

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

上级 f4154337
<template> <template>
<view> <view>
<text class="counter-text">count: {{ count }}</text> <text class="counter-text">count: {{ count }}</text>
<text class="uni-common-mt counter-btn" @click="increment"></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> </view>
</template> </template>
...@@ -10,9 +12,13 @@ ...@@ -10,9 +12,13 @@
name: 'Counter', name: 'Counter',
data() { data() {
return { return {
count: 0 count: 0,
activatedNum: 0,
deactivatedNum: 0,
} }
}, },
activated() { this.activatedNum++ },
deactivated() { this.deactivatedNum++ },
methods: { methods: {
increment() { increment() {
this.count++ this.count++
...@@ -29,4 +35,4 @@ ...@@ -29,4 +35,4 @@
border-radius: 4px; border-radius: 4px;
text-align: center; text-align: center;
} }
</style> </style>
\ No newline at end of file
...@@ -18,6 +18,11 @@ describe('keep-alive', () => { ...@@ -18,6 +18,11 @@ describe('keep-alive', () => {
const showCounterBtn = await page.$('.show-counter') const showCounterBtn = await page.$('.show-counter')
await showCounterBtn.tap() 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') const counterBtns = await page.$$('.counter-btn')
for (let i = 0; i < counterBtns.length; i++) { for (let i = 0; i < counterBtns.length; i++) {
...@@ -38,6 +43,9 @@ describe('keep-alive', () => { ...@@ -38,6 +43,9 @@ describe('keep-alive', () => {
await showCounterBtn.tap() 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') let counterTexts = await page.$$('.counter-text')
for (let i = 0; i < counterTexts.length; i++) { for (let i = 0; i < counterTexts.length; i++) {
expect(await counterTexts[i].text()).toBe('count: 1') expect(await counterTexts[i].text()).toBe('count: 1')
...@@ -58,6 +66,9 @@ describe('keep-alive', () => { ...@@ -58,6 +66,9 @@ describe('keep-alive', () => {
await showCounterBtn.tap() await showCounterBtn.tap()
expect(await activatedNum.text()).toBe('activated num: 3')
expect(await deactivatedNum.text()).toBe('deactivated num: 2')
counterTexts = await page.$$('.counter-text') counterTexts = await page.$$('.counter-text')
for (let i = 0; i < counterTexts.length; i++) { for (let i = 0; i < counterTexts.length; i++) {
expect(await counterTexts[i].text()).toBe('count: 1') 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.
先完成此消息的编辑!
想要评论请 注册