Mock fetch in vitest tests using unstable_dev
Hi! I've got an application that uses durable objects in wrangler workers. I'm trying to write some integration tests using
unstable_dev
, and it works fine until I need to fetch
from an external service, which obviously fails.
I've tried all possible ways to nock/mock/intercept these requests. I even tried to mock the method that calls fetch inside a class instance, but nothing works.
I was wondering if anyone had any ideas? I looked into using @cloudflare/vitest-pool-workers
, but it forces me to set compatibility_flags = ["nodejs_compat"]
, which I would prefer not to do. Still, I did give it a go, but I get a weird typescript error, _os.platform is not a function
.
Any help would be very much appreciated, I've spent so many hours on this and I don't know what else to try0 Replies