-
Hi ! I am trying to perform some integration tests with Mock Service Worker, where msw will reply with a 401 unauthorized. I am using OpenAPI fetch, and in particular i am using a Middleware that will throw an Error when the response code is no 2xx (exactly like described in their documentation). The idea behind that is i want to be able to use Colada's However, when running my test with Vitest, i get an unhandled error / rejection from that test:
My project branch is at https://github.com/gotson/komga/tree/next-ui
I tried changing my Colada query like so: Index: next-ui/src/colada/queries/actuator-info.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/next-ui/src/colada/queries/actuator-info.ts b/next-ui/src/colada/queries/actuator-info.ts
--- a/next-ui/src/colada/queries/actuator-info.ts (revision 41ebd3c79eb4f5c787439bf483c2721837862d48)
+++ b/next-ui/src/colada/queries/actuator-info.ts (date 1749782974529)
@@ -9,7 +9,8 @@
komgaClient
.GET('/actuator/info')
// unwrap the openapi-fetch structure on success
- .then((res) => res.data as ActuatorInfo),
+ .then((res) => res.data as ActuatorInfo)
+ .catch((x) => x),
// 1 hour
staleTime: 60 * 60 * 1000,
gcTime: false, With this i don't get the unhandled error, however expect((error.value?.cause as ErrorCause).status).toBe(401) I suppose i'm doing something wrong with the error handling. How can i achieve the behaviour i want without unhandled errors ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I don’t think the error comes from pinia colada. Otherwise, that would be a bug. Maybe it’s because of the mock with msw? Have you tried removing layers to see? In your test, the only thing I see I would change is calling the query within the component. So you createColadaMock could take a setup function to execute within the component and expose the content |
Beta Was this translation helpful? Give feedback.
Thanks for the info. I found it's a bug in defineQuery fixed in 3037012 and released