Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
vitest: cómo agregar una biblioteca de tercera parte para vue

Quiero probar mi componente vue2 personalizado que usa una biblioteca de terceros.

paquete.json

 { "@vue/test-utils": "^1", "vite": "^2.9.13", "vitest": "^0.18.1" }

Agregué un archivo de configuración para inicializar la biblioteca de la tercera parte

vite.config.js

 export default { test: { setupFiles: [ 'src/test/initial.js', ], }, }

src/prueba/inicial.js

 import { afterAll, beforeAll } from 'vitest'; import Vue from 'vue'; import PortalVue from 'portal-vue'; beforeAll(() => { Vue.use(PortalVue); console.log('initial test vue'); });

Estoy seguro de que initial.js se ha cargado desde que se imprimió la vista de initial test vue en la terminal.


en mi archivo de prueba:

 import { mount } from '@vue/test-utils'; import { describe, it, expect } from 'vitest'; import CustomDialog from '~/components/custom-dialog.vue'; const getCustomDialogWrapper = template => { return mount({ data() { return { show: false, }; }, components: { CustomDialog, }, template: ` <div> <button id="show-dialog-btn" type="button" @click="show = true"> show dialog </button> ${template} <portal-target name="dialogs-container"/> </div> ` }); } describe('custom-dialog.vue', () => { it('basic dialog without any custom props or title', async () => { const wrapper = getCustomDialogWrapper(` <custom-dialog v-model="show"> dialog content </custom-dialog> `); }); });

Pero el vitest simplemente no puede encontrar la biblioteca de la tercera parte: [Vue warn]: elemento personalizado desconocido:

ingrese la descripción de la imagen aquí

el archivo de prueba es una copia del proyecto anterior que funciona en jest + webpack, ¿cómo cargar la biblioteca de la tercera parte en vitest + vite?

¡Muchas gracias por cualquier ayuda!

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!