[Vue warn]: A plugin must either be a function or an object with an "install" function. Vue test utils
See original GitHub issueVersions
-2.0.5-rc
Describe the bug
Testing components using vueTestUtills on Vite, errors out on not being able to resolve the plugin.
Expected behavior
import VueToastificationPlugin from 'vue-toastification';
const wrapper = mount(InvoiceView, {
props: { invoiceId: '2B8B364A-A45E-4922-85CF-0334EC5D4354' },
global: {
plugins: [store, VueToastificationPlugin],
},
});
should work just fine, instead vue displays warning: [Vue warn]: A plugin must either be a function or an object with an "install" function. Vue test utils and the test errors out on TypeError: __vite_ssr_import_16__.useToast is not a function
Steps to reproduce
- create vite component that uses toastification
- write a test using vue test utils
- observe error
Issue Analytics
- State:
- Created a year ago
- Reactions:11
- Comments:14
Top Results From Across the Web
[Vue warn]:A plugin must either be a function or an object ...
I use click-outside-vue3' as directive with Nuxt3. Had the same issue. The reason was that I had: import ClickOutside from ...
Read more >[Vue warn]: A plugin must either be a function or an object ...
[Vue warn]: A plugin must either be a function or an object with an "install" function. Vue test utils. vue-toastification.
Read more >Plugins | Vue.js
A plugin is defined as either an object that exposes an install() method, or simply a function that acts as the install function...
Read more >Upgrade Guide
You will also need to make a few changes to your main.js (and also upgrade your Vue CLI project to support Vue 3)...
Read more >The Complete Guide to Vue 3 Plug-ins: Part 2
For instance, you use a Log Component in every Vue app you work on. In addition, you might expose a few global functions...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Same issue here
I got the same error, also using
viteandvitest. In the normal aplication it works, but during tests it failed. Mocking withvi.mock('vue-toastification', ...);unfortunately didn’t seem to do anything either.What I did to solve the problem for now was writing a custom (wrapped)
useToastfunction in a separate file:src/plugins/toasts/index.ts:
And in the file that you want to use it replace
import { useToast } from 'vue-toastification';withimport { useToast } from '@/plugins/toasts';Or something similar.In case you wanted to test for a toast notification to be triggered you can place a spy:
I hope this helps anyone running into this problem.