I was using jest for my web-app unit testing,but got an tough case.
I import a component in a test.spec.js file , this component imports a http request function from another file , this http request function use the var I defined in the vuex state,and this state data use the window object, which cause the test file error.Here's some codes.
test.spec.js: imports a component called Info.vue
import Info from '@/pages/user/Info.vue'
Info.vue: imports a http request function requestData
from get-api-data.js
import { requestData } from '@/service/get-api-data'
get-api-data.js: imports the store(vuex) data
import store from '@/store'
store have those vars which involve the window object:
env: {
apiUrl: window._env.apiUrl,
name: window._env.user,
password: window._env.apiKey
},