vuejs / vue-test-utils

Component Test Utils for Vue 2
https://vue-test-utils.vuejs.org
MIT License
3.57k stars 669 forks source link

Error: [vite-node] Failed to load node_modules/vitest/dist/index #1994

Closed leongaban closed 1 year ago

leongaban commented 2 years ago

Subject of the issue

I am getting the following error when trying to use mount

Error: [vite-node] Failed to load node_modules/vitest/dist/index

Steps to reproduce

I have the latest version of vue/test-utils: "@vue/test-utils": "^2.0.2"

Basic vite-config

import { fileURLToPath, URL } from 'url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

// https://vitejs.dev/config/
export default defineConfig({
  test: {
    globals: true,
  },
  plugins: [vue(), vueJsx()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})

The test:

import { mount } from '@vue/test-utils'
import { expect } from 'node_modules/vitest/dist/index'
import HomeHeader from '../HomeHeader.vue'

test('HomeHeader renders properly', () => {
    expect(HomeHeader).toBeTruthy()
    const wrapper = mount(HomeHeader)
    expect(wrapper.text()).toContain('MOONHOLDINGS.XYZ')
})

Expected behaviour

Test should pass

Actual behaviour

Error:

 FAIL  src/components/home/__tests__/HomeHeader.spec.js [ src/components/home/__tests__/HomeHeader.spec.js ]
Error: [vite-node] Failed to load node_modules/vitest/dist/index

Possible Solution

I've updated both @vue/test-utils and vitest to the latest, also watched this tutorial video: https://www.youtube.com/watch?v=snCLQmINqCU

ebisbe commented 1 year ago

This repository is for issues regarding Vue-test utils V1 . For V2 related you have to go https://github.com/vuejs/test-utils