Vue + Jest Не могу прочитать свойство 'default' из неопределенного - PullRequest
2 голосов
/ 07 февраля 2020

Я получаю эту ошибку, и я не знаю, что ее вызывает.
TypeError: Невозможно прочитать свойство 'default' из неопределенного
Я начал возиться с тестами сейчас, если ошибка глупая, я извиняюсь

Приложение. 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>

Пакет. 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- Страница утилит, это самый простой c пример example.spe c. 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()
  })
})

Если кто-то может помочь мне найти мою ошибку, я был бы очень признателен.

...