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

test: 修复 keepAlive 组件非预期触发 update 生命周期后更新测试例

上级 af1c47ed
......@@ -40,8 +40,8 @@ describe('component-lifecycle', () => {
await toggleAliveComponentBtn.tap()
lifeCycleNum = await page.callMethod('pageGetLifeCycleNum')
// TODO: android 端 keep-alive 组件切换时,不触发 activated, 会触发 beforeUpdate updated
expect(lifeCycleNum).toBe(isAndroid ? 114 : 113)
// TODO: android 端 组合式 API 不触发 activated
expect(lifeCycleNum).toBe(isAndroid ? 112 : 113)
await page.callMethod('pageSetLifeCycleNum', 0)
})
it('onBeforeUpdate onUpdated', async () => {
......
......@@ -7,8 +7,9 @@
<keep-alive>
<component :is="aliveComponent" @updateIsScroll="updateIsScroll" />
</keep-alive>
<button class="mt-10" @click="scrollToBottom">scrollToBottom</button>
<button class="mt-10" @click="scrollToBottom">scrollToBottom</button>
<button id="toggle-alive-component-btn" class="mt-10" @click="toggleAliveComponent">toggle alive component</button>
<button class="mt-10" @click="navigateToHome">navigateTo home</button>
</view>
<!-- #ifdef APP -->
</scroll-view>
......@@ -61,6 +62,12 @@
// 自动化测试
const getIsScrolled = () : boolean => {
return isScrolled.value
}
const navigateToHome = () => {
uni.navigateTo({
url: '/pages/index/index'
})
}
defineExpose({
......
......@@ -4,8 +4,6 @@ const HOME_PATH = '/pages/index/index'
describe('component-lifecycle', () => {
let page
let lifeCycleNum
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.includes('android')
beforeAll(async () => {
page = await program.reLaunch(HOME_PATH)
await page.waitFor(700)
......@@ -33,20 +31,19 @@ describe('component-lifecycle', () => {
await toggleAliveComponentBtn.tap()
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(4)
// TODO: android 端 keep-alive 组件切换时,不仅触发 activated, 之前还会触发 beforeUpdate updated
await toggleAliveComponentBtn.tap()
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(isAndroid ? 7 : 5)
expect(lifeCycleNum).toBe(5)
})
it('beforeUpdate updated', async () => {
const updateTitleBtn = await page.$('.component-lifecycle-btn')
await updateTitleBtn.tap()
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(isAndroid ? 9 : 7)
expect(lifeCycleNum).toBe(7)
})
it('deactivated beforeUnmount unmounted', async () => {
page = await program.navigateBack()
lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(isAndroid ? 6 : 4)
expect(lifeCycleNum).toBe(4)
})
})
\ No newline at end of file
......@@ -4,7 +4,8 @@
<keep-alive>
<component :is="aliveComponent" />
</keep-alive>
<button id="toggle-alive-component-btn" class="mt-10" @click="toggleAliveComponent">toggle alive component</button>
<button id="toggle-alive-component-btn" class="mt-10" @click="toggleAliveComponent">toggle alive component</button>
<button class="mt-10" @click="navigateToHome">navigateTo home</button>
</view>
</template>
......@@ -26,6 +27,11 @@ export default {
},
toggleAliveComponent(){
this.aliveComponent = this.aliveComponent == null ? ChildComponent : null
},
navigateToHome() {
uni.navigateTo({
url: '/pages/index/index'
})
}
},
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册