Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

yassilah/vite-plugin-nuxt-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nuxt + Vitest = ☀️

This is a simple plugin that will add some basic configuration for Vitest to run properly inside your Nuxt 3 application (autoimports, aliases, etc.).

Installation

// vitest.config.ts
import { defineConfig } from 'vitest/config'
import NuxtVitest from 'vite-plugin-nuxt-test'

export default defineConfig({
    plugins: [NuxtVitest()],
    test: {
        // Your own configuration
    }
})

Usage

You may then use Vitest to test your composables without worrying about auto-imported methods.

// composables/useBar.ts
export function useBar() {
    return 'bar'
}
// composables/useFoo.ts
export function useFoo() {
    return useBar() + '-foo'
}
import { describe, test } from 'vitest'

describe('useFoo', () => {
    it ('should not need to be imported', () => {
        expect(useFoo).toBeDefined() // ✅
    })

    it ('should auto-import useBar as well', () => {
        expect(useFoo()).toBe('bar-foo') // ✅
    })
})

About

A vite plugin to use Vitest inside a Nuxt 3 application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published