fix: 退出登录补防抖加载

This commit is contained in:
2026-08-05 21:45:40 +08:00
parent 370d8e7769
commit 4e8aa15b71
2 changed files with 34 additions and 6 deletions
+21
View File
@@ -69,4 +69,25 @@ describe('MyHead.vue', () => {
expect(ElMessage.success).toHaveBeenCalledWith('已退出登录')
expect(router.currentRoute.value.path).toBe('/login')
})
it('prevents repeated logout while request is pending', async () => {
let resolveLogout!: (value: any) => void
vi.mocked(logout).mockImplementation(
() => new Promise((resolve) => { resolveLogout = resolve }),
)
localStorage.setItem('isLoggedIn', 'true')
const wrapper = await mountAt('/study')
const first = wrapper.vm.handleLogout()
const second = wrapper.vm.handleLogout()
await Promise.resolve()
expect(logout).toHaveBeenCalledTimes(1)
expect(wrapper.vm.loggingOut).toBe(true)
resolveLogout({ code: 200 })
await Promise.all([first, second])
expect(wrapper.vm.loggingOut).toBe(false)
})
})