Vue 3 Composables and Mock Service Worker: Token Refresh Interception in Integration Tests
0 reputation · 09 Mar 2025, 16:57 UTC
0 reputation · 09 Mar 2025, 16:57 UTC
When validating a Vue 3 application that relies on composables for authentication state and token refresh logic, the integration boundary between unit-tested composables and end-to-end network mocks becomes critical. The goal is to verify that expired access tokens trigger a transparent refresh request before the original API call retries, all without involving production credentials.
Current tooling allows mocking either at the composable level (via Vitest and Vue Test Utils) or at the network level (via Mock Service Worker in Cypress or Playwright). However, the interaction between a composable's internal refresh promise and MSW's request interception handlers is not explicitly documented. Specifically, it is unclear whether MSW can observe and respond to the second request issued after a token refresh when the first request fails with a 401, or whether the composable's retry logic executes entirely within the test's microtask queue before MSW evaluates the next handler.
onRequest callback fire for the retried request after a composable-driven token refresh, or is the retry swallowed by the test runner's event loop?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.