N
Nuxt6mo ago
w7a9q

Mocking useStorage

I'm trying to mock useStorage() as in documentation: https://nuxt.com/docs/getting-started/testing#mocknuxtimport However I'm stuck at Error: Cannot find import "useStorage" to mock. Where should I take this import from when it's autoimported by Nitro?
Nuxt
Testing · Get Started with Nuxt
How to test your Nuxt application.
3 Replies
w7a9q
w7a9qOP6mo ago
I tried this solution: https://stackoverflow.com/questions/74993530/how-to-test-a-function-that-uses-nitros-usestorage Now the error is thrown from the actual function: ReferenceError: useStorage is not defined - that should beeen autoimported as well. In the post he changes the actual implementation to use mock, I don't want this. What is the best practice about this?
Stack Overflow
How to test a function that uses Nitro's useStorage
I have created a function that allows to manage caching. I use this function to cache the responses to API calls. export const cache = async (key: string, callback: Function) => { const cach...
w7a9q
w7a9qOP6mo ago
I have tried adding @vueuse/core package and then importing the function from it: import { useStorage } from '@vueuse/core'. It did not solve the problem. Here is the StackBlitz repl: https://stackblitz.com/edit/nuxt-starter-bf2fpu?file=test%2Futils.test.ts
mfnkwimfwef
StackBlitz
Nuxt - Starter (forked) - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
w7a9q
w7a9qOP6mo ago
Looks like Nitro is not accessible outside of server: https://github.com/nuxt/nuxt/issues/23484#issuecomment-1742010287
GitHub
Default Persistent Data Storage Import is broken? · Issue #23484 · ...
Environment ~/projects/github-jt6ucm ❯ npx nuxi info [22:25:02] Working directory: /home/projects/github-jt6ucm [22:25:02] Nuxt project info: Operating System: Linux Node Version: v18.18.0 Nuxt Ver...
Want results from more Discord servers?
Add your server