primefaces / primevue

Next Generation Vue UI Component Library
https://primevue.org
MIT License
10k stars 1.2k forks source link

I am getting primevue error with vue jest test. #2244

Closed qwerty3858 closed 1 year ago

qwerty3858 commented 2 years ago

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()

But the error is not resolved.

In Primevue, where I do not use useToast or UseConfirm, I can test without getting an error. How can I solve this error?

bgozneli commented 2 years ago

Were you able to find a solution for this?

qwerty3858 commented 2 years ago

yes, ı solved, Solve is here.

const wrapper = mount(VehicleInfoDialog, { global: { plugins: [PrimeVue, ToastService, ConfirmationService] }, props: { operation: 1 } })

bahadirsofuoglu commented 1 year ago

Thank you for sharing your solution.

mtirimie1 commented 1 year ago

I am encountering the same issue as above, just using useToast() on the latest version in jest, and the above solution does not solve the issue of "No PrimeVue Toast provided!"

iyanaiExtendas commented 7 months ago

I am encountering the same issue as above, just using useToast() on the latest version in jest, and the above solution does not solve the issue of "No PrimeVue Toast provided!"

Hi, I am facing the same issue. Did you manage to find a solution for this?