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

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

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