Skip to content

Commit 75f1fbf

Browse files
Resul AvanResul Avan
Resul Avan
authored and
Resul Avan
committed
unit tests initial
1 parent ddd4ed1 commit 75f1fbf

File tree

6 files changed

+67
-23
lines changed

6 files changed

+67
-23
lines changed

src/jest.config.js

-18
This file was deleted.

src/package.json

+38-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@
2020
"husky": {
2121
"hooks": {}
2222
},
23+
"jest": {
24+
"verbose": true,
25+
"setupFiles": [
26+
"<rootDir>/tests/jest-mocks.ts"
27+
],
28+
"snapshotSerializers": [
29+
"jest-serializer-vue"
30+
],
31+
"moduleNameMapper": {
32+
"^@/(.*)$": "<rootDir>/$1",
33+
"^~/(.*)$": "<rootDir>/$1",
34+
"^vue$": "vue/dist/vue.common.js"
35+
},
36+
"moduleFileExtensions": [
37+
"ts",
38+
"js",
39+
"vue",
40+
"json"
41+
],
42+
"transform": {
43+
"^.+\\.ts$": "ts-jest",
44+
".*\\.(vue)$": "vue-jest"
45+
},
46+
"collectCoverage": true,
47+
"collectCoverageFrom": [
48+
"<rootDir>/components/**/*.{ts,vue}",
49+
"<rootDir>/pages/**/*.vue"
50+
]
51+
},
2352
"dependencies": {
2453
"@fortawesome/fontawesome-free": "^5.14.0",
2554
"@mdi/font": "^5.4.55",
@@ -68,16 +97,17 @@
6897
"vuex-class": "^0.3.2"
6998
},
7099
"devDependencies": {
100+
"@babel/core": "^7.7.7",
101+
"@babel/preset-env": "^7.11.0",
71102
"@nuxt/babel-preset-app": "^2.14.0",
72103
"@nuxt/types": "^2.14.0",
73104
"@nuxt/typescript-build": "^2.0.2",
74105
"@nuxtjs/eslint-config-typescript": "^3.0.0",
75106
"@nuxtjs/eslint-module": "^2.0.0",
76107
"@nuxtjs/stylelint-module": "^4.0.0",
108+
"@types/jest": "^26.0.8",
77109
"@types/vfile-message": "^2.0.0",
78-
"@vue/test-utils": "^1.0.3",
79110
"babel-eslint": "^10.1.0",
80-
"babel-jest": "^26.1.0",
81111
"core-js": "^3.6.5",
82112
"dts-generator": "^3.0.0",
83113
"eslint": "^7.5.0",
@@ -88,13 +118,16 @@
88118
"eslint-plugin-vue": "^6.2.2",
89119
"firebase-tools": "^8.6.0",
90120
"husky": "^4.2.5",
91-
"jest": "^26.1.0",
121+
"jest-serializer-vue": "^2.0.2",
92122
"lint-staged": "^10.2.11",
93123
"node-sass": "^4.14.1",
94124
"prettier": "^2.0.5",
95125
"sass-loader": "^9.0.2",
96126
"stylelint": "^13.6.1",
97-
"ts-jest": "^26.1.3",
98-
"vue-jest": "^4.0.0-0"
127+
"@vue/test-utils": "^1.0.0-beta.27",
128+
"babel-jest": "^24.1.0",
129+
"jest": "^24.1.0",
130+
"vue-jest": "^4.0.0-0",
131+
"ts-jest": "^25.0.0"
99132
}
100133
}

src/tests/jest-mocks.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { config } from '@vue/test-utils'
2+
config.mocks.$t = (key: string) => key
3+
config.showDeprecationWarnings = false

src/tests/pages/index.spec.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { mount } from '@vue/test-utils'
2+
import Vue from 'vue'
3+
import Index from '~/pages/index.vue'
4+
5+
Vue.config.ignoredElements = ['b-icon']
6+
7+
// const head = (): MetaInfo => {
8+
// return null
9+
// }
10+
11+
describe('HomePage', () => {
12+
const wrapper = mount(Index)
13+
14+
it('is a Vue component', () => {
15+
expect(wrapper.vm).toBeTruthy()
16+
// expect(wrapper.vm.$meta()).toBeCalled()
17+
})
18+
19+
// it('check page title', () => {
20+
// // const spy = jest.spyOn(Index, 'head')
21+
// // @ts-ignore
22+
// expect(wrapper.vm.head()).toHaveBeenCalled()
23+
// })
24+
})
File renamed without changes.

src/tsconfig.json

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"types": [
3030
"@types/node",
3131
"@nuxt/types",
32+
"@nuxt/vue-app",
33+
"@types/jest",
3234
"@nuxtjs/axios",
3335
"nuxt-i18n",
3436
"cookie-universal-nuxt",

0 commit comments

Comments
 (0)