I am getting primevue error with vue jest test
Asked Answered
C

1

2

I am writing a test with Vue jest. But when I say run:test "No PrimeVue Confirmation provided!" It shows that this error is caused by useToast() and useConfirm() services.

"transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!primevue/.*)"
    ]

I pasted this where I wrote the jest and the final version was as follows.

   "jest": {
    "preset": "@vue/cli-plugin-unit-jest",
    "transform": {
      "^.+\\.vue$": "vue-jest"
    },
    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!primevue/.*)"
    ]
  }

It continued to give errors in this state.

I also added PrimeVue globally in the .spec.js file I wrote a test for.

import PrimeVue from "primevue/config";

  const wrapper = mount(VehicleInfo, {
      global:{
        plugins: [PrimeVue]
      },
      props: { nationCode:1 }
    })

error is here:

   No PrimeVue Confirmation provided!

      66 |     })
    > 67 |     const confirm = useConfirm()
         |                     ^
      68 |     const toast=useToast()
Chamorro answered 12/3, 2022 at 11:31 Comment(0)
D
3

This worked for me:

import { useConfirm } from 'primevue/useconfirm';
import PrimeVue from 'primevue/config';
import ConfirmationService from 'primevue/confirmationservice';

const wrapper = shallowMount(MyComponent, {
  props: { aProp },
  global: {
    components: { useConfirm },
    plugins: [PrimeVue, ConfirmationService],
  },
});
Diabolic answered 17/3, 2022 at 16:9 Comment(1)
Also, I think the problem with file formats that required you to add transformIgnorePatterns for primevue files has gone away, so you should not need that anymore.Diabolic

© 2022 - 2024 — McMap. All rights reserved.