Skip to content

Instantly share code, notes, and snippets.

@devinschumacher
Created November 12, 2024 02:54
Show Gist options
  • Select an option

  • Save devinschumacher/7559ec13083a5465b48a922ec61bdaee to your computer and use it in GitHub Desktop.

Select an option

Save devinschumacher/7559ec13083a5465b48a922ec61bdaee to your computer and use it in GitHub Desktop.
How to enable vitest auto imports (globals)
title How to enable vitest auto imports (globals)
tags
vitest
globals
testing
tsconfig
nuxt
vue

How to enable vitest auto imports (globals) in Vue/Nuxt

  1. Add globals to the vitest config (or vite config) in the defineConfig object
// vitest.config.ts

defineConfig({
  // ..
  test: {
    globals: true,
  }
  // ..
})
  1. (if you're using typescript): Add "vitest/globals" to your typescript config

If you're using typescript, you'll need to let your IDE know about these types by adding this to your typescript config under the "compilerOptions" object.

// tsconfig.json OR tsconfig.vitest.json
{
  // ...
  "compilerOptions": {
    // ...
    "types": ["vitest/globals"]
  }
  // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment