I am getting the following error when trying to write a component test:
Cannot find module ‘primevue/config’ from ‘src/../Component.test.js’
I am using Vue v3, Vue CLI (to run the test), Jest v29, Testing Library (Vue) v8 and PrimeVue v4. PrimeVue is a Vue component library that needs to be installed in your Vue app.
Here’s the code for my test file:
import { render, screen } from '@testing-library/vue'
import PrimeVue from 'primevue/config'
import MyComponent from '../MyComponent.vue'
test('Renders MyComponent', async () => {
render(MyComponent, {
global: {
plugins: [PrimeVue],
},
})
const title = screen.getByText('MyTitle')
expect(title).not.toBeNull()
})
Here’s my jest.config.js
:
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
testEnvironmentOptions: {
customExportConditions: ['node'],
},
}
And finally, tests are run via:
vue-cli-service test:unit
I tried downgrading Jest prior to v28 (where jest-environment-jsdom
was not an external dependency); tried different config options for Jest and also tried to run the tests without using Vue CLI Service; but nothing seems to fix the problem.
Any directions would be appreciated!