N
Nuxt7mo ago
Tumulte

How to mock useRoute in nuxt ?

I would just like to access route.params.id in vitest BUT, I cannot mock useRoute the way we used to in Nuxt. No matter what, route.params.id is undefined I've tried seting up a route in mountSuspended but to no success. What's the proper way ? Thanks
2 Replies
dwol
dwol7mo ago
have you tried something like:
mockNuxtImport('useRoute', () => {
return () => (
{
path: 'some-path,
params: {
param: 'value'
},
// rest of the route object
}
)
})
mockNuxtImport('useRoute', () => {
return () => (
{
path: 'some-path,
params: {
param: 'value'
},
// rest of the route object
}
)
})
Tumulte
TumulteOP7mo ago
no and I wasn't aware of this utility thank a lot !
Want results from more Discord servers?
Add your server