Jest Configuration:
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'vue'],
moduleNameMapper: {
'^~/(.*)$': '<rootDir>/src/$1',
},
testEnvironment: 'jsdom',
testMatch: ['**/tests/unit/**/*.[jt]s?(x)'],
transform: {
'^.+\\.vue$': 'vue-jest',
'^.+\\.ts$': 'ts-jest',
},
}
My test file (.ts file) :
import { render } from '@testing-library/vue'
import Kaki from '~/components/Kaki.vue'
test('Kaki.vue', () => {
const { getByText } = render(Kaki)
getByText('Tono')
})
Here's my directory structure:
When I run the test, it says Cannot find module '~/components/Kaki.vue' or its corresponding type declarations.
I think it has something to do with moduleNameMapper