我遇到此错误,我不知道是什么原因引起的。
TypeError:无法读取未定义的属性“默认”
我现在开始搞乱测试,如果错误很愚蠢,我道歉
App.vue
<template>
<div id="app">
<div :class="{'d-flex': !isMobile(), 'd-flex toggled':isMobile()}" id="wrapper">
<lateral v-if="rota != '/login'" :show="show" />
<div id="page-content-wrapper">
<topo v-if="rota != '/login'" @show="show = $event" />
<router-view />
</div>
</div>
</div>
</template>
<script>
import mapa from "@/components/painel/mapa.vue";
import topo from "@/components/painel/topo.vue";
import lateral from "@/components/painel/lateral.vue";
import { mapActions, mapGetters, mapState } from "vuex";
export default {
components: { topo, lateral, mapa },
data() {
return {
rota: this.$route.path,
show: undefined
};
},
mounted() {
if (this.accountId == undefined) {
this.Me();
}
},
computed: {
...mapState("login", ["accountId"]),
...mapGetters("login", ["getAccountId"]),
...mapGetters("property", ["getProperties"])
},
watch: {
$route(to, from) {
this.rota = to.path;
document.title = "AgroInteli "+to.name
},
getAccountId(to, from) {
this.Account(to).then(resp => this.SetProperty());
}
},
methods: {
...mapActions("login", ["Me"]),
...mapActions("property", ["Account", "SelectProperty", "SelectCrops"]),
SetProperty() {
if (this.getProperties.length > 0) {
let property =
sessionStorage.getItem("property") == null
? this.getProperties[0]
: JSON.parse(sessionStorage.getItem("property"));
this.SelectProperty(property);
let crop = property.crops == undefined ? [] : property.crops;
if (crop.length > 0) this.SelectCrops(crop[0]);
}
},
isMobile() {
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
return true
} else {
return false
}
},
},
};
</script>
<style scoped lang="scss">
#app {
height: 100%;
width: 100%;
}
</style>
Package.json
{
"name": "agroninteli-web-vue",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test": "jest"
},
"dependencies": {
"@fullcalendar/core": "^4.3.1",
"@fullcalendar/daygrid": "^4.3.0",
"@fullcalendar/interaction": "^4.3.0",
"@fullcalendar/timegrid": "^4.3.0",
"@fullcalendar/vue": "^4.3.1",
"axios": "^0.19.0",
"babel-preset-env": "^1.7.0",
"chart.js": "^2.9.3",
"core-js": "^3.3.2",
"html2canvas": "^1.0.0-rc.5",
"html2pdf.js": "^0.9.1",
"jspdf": "^1.5.3",
"jspdf-autotable": "^3.2.11",
"leaflet": "^1.6.0",
"register-service-worker": "^1.6.2",
"vue": "^2.6.10",
"vue-carousel": "^0.18.0",
"vue-docgen-api": "^4.7.6",
"vue-json-excel": "^0.2.98",
"vue-router": "^3.1.3",
"vue-toastify": "^1.0.3",
"vue2-leaflet": "^2.2.1",
"vueperslides": "^2.2.0",
"vuex": "^3.0.1"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.8.3",
"@vue/cli-plugin-babel": "^4.0.0",
"@vue/cli-plugin-pwa": "^4.0.0",
"@vue/cli-plugin-unit-jest": "^4.0.0",
"@vue/cli-service": "^4.0.0",
"@vue/test-utils": "^1.0.0-beta.29",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^25.1.0",
"babel-plugin-syntax-class-properties": "^6.13.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-vue": "^2.0.2",
"jest": "^25.1.0",
"jest-transform-stub": "^2.0.0",
"node-sass": "^4.12.0",
"sass-loader": "^7.1.0",
"stylus": "^0.54.7",
"stylus-loader": "^3.0.2",
"vue-jest": "^3.0.5",
"vue-template-compiler": "^2.6.10"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
".*\\.(vue)$": "vue-jest",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
"\\.js$": "<rootDir>/node_modules/babel-jest",
".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
},
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
},
"transformIgnorePatterns": [
"node_modules/(?!@ngrx|(?!deck.gl)|ng-dynamic)"
]
}
}
我从vue-test-utils页面中获取了此示例,这是最基本的示例 example.spec.js
import { mount } from '@vue/test-utils'
import main from '@/App.vue'
describe('Component', () => {
test('is a Vue instance', () => {
const wrapper = mount(main)
console.log(wrapper)
expect(wrapper.isVueInstance()).toBeTruthy()
})
})
如果有人可以帮助我找到我的错误,我将非常感激。
答案 0 :(得分:0)
尝试一下(为我工作):
test('is a Vue instance', () => {
const wrapper = mount(main)
expect(wrapper.vm).toBeTruthy()
})