i got the current jest config setup as the following:
module.exports = {
testEnvironment: 'jsdom',
transform: {
'^.+\\.vue$': '@vue/vue3-jest',
'^.+\\js$': 'babel-jest'
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js)$',
moduleFileExtensions: ['vue', 'js'],
transformIgnorePatterns: ['/node_modules/(?!@ionic/vue|@ionic/vue-router|@ionic/core|@stencil/core|ionicons)']
}
However this cause an issue when adding a simple vue test:
import { mount } from '@vue/test-utils'
import HomePage from '@/views/HomePage.vue'
describe('HomePage.vue', () => {
it('renders home vue', () => {
const wrapper = mount(HomePage)
expect(wrapper.text()).toMatch('Ready to create an app?')
})
})
The @ symbol isn't resolved as wanted:
● Test suite failed to run
Cannot find module '@/views/HomePage.vue' from 'tests/unit/example.spec.js'
1 | import { mount } from '@vue/test-utils'
> 2 | import HomePage from '@/views/HomePage.vue'
| ^
3 |
4 | describe('HomePage.vue', () => {
5 | it('renders home vue', () => {
at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
at Object.<anonymous> (tests/unit/example.spec.js:2:1)
However, adding
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
within the jest.config.js file give me this error:
● Test suite failed to run
Cannot find module 'ts-jest/dist/config/config-set'
Installing ts-jest & typescript would work, but is there any way to fix this issue without having to deal with typescript?