How to mock useAsyncData in combination with registerEndpoint #1201
Unanswered
martijnhalekor
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I understood it's not possible to use
mockNuxtImport
foruseAsyncData
and have it return different data in different tests in the same file. As is mentioned in the Nuxt docs and by Alex in his Primer to Testing in Nuxt video.I managed to setup some basic unit tests by using
registerEndpoint
to mock external API calls. For that to work, I had to split up my app.vue test into 3 separate tests (header, main, footer), because they all useuseAsyncData
.I was wondering if there's any way to have
useAsyncData
return the mocked data fromregisterEndpoint
? The only way I can think of is to rewrite my components fromuseAsyncData
touseFetch
, so the registerEndpoint mocks can be used, but I'd rather find a way to test my components without having to refactor them. Or am I chasing something impossible?Beta Was this translation helpful? Give feedback.
All reactions