๋ฐ์ํ
๐พ pacakge.json ์ค์น
npm install --save-dev jest @vue/test-utils
npm i @vue/vue3-jest
npm install --save-dev @vue/test-utils
npm install --save-dev ts-jest
npm install --save-dev @types/jest
npm install --save-dev @babel/core
npm install --save-dev @babel/preset-env
npm install --save-dev @babel/preset-typescript
npm install --save-dev jest-environment-jsdom
npm install --save-dev jest-transform-stub
๐ tsconfig.json(ํ์ ์คํฌ๋ฆฝํธ ํ๊ฒฝ)
{
"compilerOptions": {
"types": [
"jest"
]
}
}
๐ฆถ babel.config.json
{
"presets": ["@babel/preset-env","@babel/preset-typescript"]
}
๐ง jest.config.js(jest ํ๊ฒฝ์ธํ )
module.exports = {
moduleFileExtensions: [
'js',
'ts',
'json',
// ๋ชจ๋ vue ํ์ผ(`*.vue`)์ ์ฒ๋ฆฌํ๊ธฐ ์ํด Jest์๊ฒ ์๋ ค์ค๋๋ค
'vue'
],
transform: {
// process `*.vue` files with `vue-jest`
'.*\\.(vue)$': '@vue/vue3-jest',
'^.+\\.tsx?$': 'ts-jest',
'.*\\.(js)$': 'babel-jest',
'.*\\.(ts)$': 'babel-jest',
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub'
},
moduleNameMapper: {
// ๋ณ์นญ @(ํ๋ก์ ํธ/src) ์ฌ์ฉํ์ฌ ํ์ ๊ฒฝ๋ก์ ํ์ผ์ ๋งตํํฉ๋๋ค
'^@/(.*)$': '<rootDir>/src/$1'
},
testMatch: ['**/*.spec.[jt]s?(x)', '**/*.test.[jt]s?(x)'],
// node_modules ๊ฒฝ๋ก ํ์์ ์๋ ๋ชจ๋ ํ
์คํธ ํ์ผ์ ๋์์์ ์ ์ธํฉ๋๋ค
testPathIgnorePatterns: ['/node_modules/'],
testEnvironment: 'jsdom',
testEnvironmentOptions: {
customExportConditions: ['node', 'node-addons']
},
transformIgnorePatterns: ['node_modules/(?!@ngrx|(?!deck.gl)|ng-dynamic)']
};
๐ง package.json(๋ช ๋ น์ด ๋ฑ๋ก)
{
"scripts": {
"test:unit": "jest --watchAll"
}
}
๐ถ๋ช ๋ น์ด ์คํ
npm run test:unit๋ฐ์ํ
'Vue' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| props์ผ๋ก ํจ์ ๋ฐ๊ธฐ (0) | 2023.07.23 |
|---|---|
| ๐ vscode ์์ EditorConfig ์ฐ๊ธฐ (0) | 2023.06.02 |
| ๐ฒ vue + jest๋ฅผ ์ด์ฉํ login ๊ตฌํ (0) | 2023.04.11 |
| ๐ vue jest router ์๊ธด ๋ฌธ์ (0) | 2023.03.16 |
| ๐ vue jest study๊ธฐ๋ก (0) | 2023.03.03 |
๋๊ธ