Files
shiftcraft/.claude/skills/nuxt-testing/references/unit-mocks.md
2026-04-17 23:26:01 +00:00

715 B

Built-In Mocks

@nuxt/test-utils provides built-in mocks for browser APIs in the DOM test environment.

intersectionObserver

  • Default: true
  • Creates a dummy class without any functionality for the IntersectionObserver API.

indexedDB

  • Default: false
  • Uses fake-indexeddb to create a functional mock of the IndexedDB API.

Configuration

// vitest.config.ts
import { defineVitestConfig } from '@nuxt/test-utils/config'

export default defineVitestConfig({
  test: {
    environmentOptions: {
      nuxt: {
        mock: {
          intersectionObserver: true,
          indexedDb: true,
        },
      },
    },
  },
})