h2o
h2o
NNuxt
Created by h2o on 11/6/2024 in #❓・help
Test for nitro storage
I want to test if the nitro storage returns a certain item. How do I write a test for it? In my endpoint I use a server util with the function getContent(path), that's what I want to unit test. It's a server plugin that sets up the storage in the first place.
import { useNitroApp } from '#internal/nitro/app'

export async function getContent (path) {
const nitroApp = useNitroApp()
const storageType = 'website'
const db = nitroApp[`${storageType}ContentStorage`]
const res = await db.getItem(path.replace(/\//g, ':'))
return res
}
import { useNitroApp } from '#internal/nitro/app'

export async function getContent (path) {
const nitroApp = useNitroApp()
const storageType = 'website'
const db = nitroApp[`${storageType}ContentStorage`]
const res = await db.getItem(path.replace(/\//g, ':'))
return res
}
6 replies