NuxtN
Nuxt15mo ago
5 replies
h2o

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
}
Was this page helpful?