useStorage in nuxt/test-utils
I'm trying to use
useStorage()
in vitest unit test. I'm using nuxt/test-utils
package.
Normally in my code useStorage()
is auto imported but in the test it's not the case. How can I make it work?
This snipped fails at: ReferenceError: useStorage is not defined
5 Replies
Bump. I'm interested in solution too. How to handle/mock auto imported composables.
I'd mock useStorage here instead, e.g. via
mockNuxtImport
That doesn't solve the issue when I want to test a function that saves an item to the storage. I want to load the item afterwards and perform assertion on it.
but then you test the behavior of
useStorage
which isn't under your control
but what you could do is add a route only available in test which returns that item via useStorage. that might be a workaround if you really need itSo you think it's bad designed test?
The point of the function is to process the object and save some of the properties to the KV. I need to verify that the content saved into the KV is correct.