You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Cannot read properties of undefined" whenever we try to access something like "$vuetify" on a Vue instance.
Possible Solution
No solutions, but some workarounds:
Workaround 1: Monkey-one of my colleagues found a workaround. However, it's a bit arduous when there are many tests:patch the require function in tests (yuck)
Use alias vue: "vue/dist/vue.common.js" instead of vue: "vue/dist/vue.esm.js".
Create a utility function
exportfunctionforceVueAlias(overwrite: string){// Load global module.constglobalModule=require('module');// Save original require method.const_require=globalModule.prototype.require;globalModule.prototype.require=function(){if(arguments["0"]==="vue")arguments["0"]=overwrite;// Return result from original function.greturn_require.apply(this,arguments);};}
Use it at the top of every test:
forceVueAlias("vue/dist/vue.common.js");
Workaround 2:
Don't use aliases. But then I can't have the runtime compiler for my project, which is a big problem.
Workaround 3:
import{defineConfig,loadEnv}from"vite";exportdefaultdefineConfig(({ command, mode })=>{constenv=loadEnv(mode,process.cwd(),"");return{resolve: {alias: {// This enables the runtime compiler for Vue 2.vue: "vue/dist/vue.esm.js",},},test: {alias: {// Disable the runtime compiler during tests.vue: "vue",},},};});
The text was updated successfully, but these errors were encountered:
The above-mentioned "workaround 1" causes a few other problems, where some getCurrentInstance is returning null inside some composables, like useRoute. Not sure why, yet. It would be great if there was a way to either
let vitest respect the resolve.alias
enable runtime compiler in the actual app AND in tests without using aliases
rudolfbyker
changed the title
Vite resolve.alias is not respected
Vite resolve.alias causes some tests to fail
Apr 11, 2023
Subject of the issue
It looks like vitest is not respecting the
resolve.alias
setting from thevite
config file.Steps to reproduce
See https://github.com/rudolfbyker/vitest-vue2-vuetify-repro
Expected behaviour
The test should pass.
Actual behaviour
"Cannot read properties of undefined" whenever we try to access something like "$vuetify" on a Vue instance.
Possible Solution
No solutions, but some workarounds:
Workaround 1: Monkey-one of my colleagues found a workaround. However, it's a bit arduous when there are many tests:patch the require function in tests (yuck)
vue: "vue/dist/vue.common.js"
instead ofvue: "vue/dist/vue.esm.js"
.Workaround 2:
Don't use aliases. But then I can't have the runtime compiler for my project, which is a big problem.
Workaround 3:
The text was updated successfully, but these errors were encountered: