开玩笑-配置Vuex映射器和Vue惰性组件

时间:2018-11-19 10:43:41

标签: vue.js jestjs babeljs nuxt

我正在尝试在项目中设置jest。我很想测试由...mapState...mapActions...mapGetters创建的Vuex存储的计算属性,但是jest无法读取它们:

enter image description here

第二个问题是延迟加载的Vue组件:

enter image description here

Jest 配置

  "jest": {
    "verbose": true,
    "moduleFileExtensions": [
      "js",
      "vue",
      "json"
    ],
    "snapshotSerializers": [
      "jest-serializer-vue"
    ],
    "moduleNameMapper": {
      "^~/(.*)$": "<rootDir>/$1"
    },
    "transform": {
      "^.+\\.vue$": "vue-jest",
      ".+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub",
      "^.+\\.(js|jsx)?$": "babel-jest"
    },
    "transformIgnorePatterns": [
      "node_modules/"
    ]
  },

.babelrc文件:

{
  "presets": [
    "env"
  ]
}

"devDependencies": {
    "@vue/test-utils": "^1.0.0-beta.25",
    "babel-eslint": "^8.2.6",
    "babel-jest": "^23.6.0",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-preset-env": "^1.7.0",
    "cross-env": "^5.0.1",
    "eslint": "^5.6.1",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-loader": "^2.0.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-jest": "^21.26.1",
    "eslint-plugin-vue": "^5.0.0-beta.3",
    "jest": "^23.6.0",
    "jest-serializer-vue": "^2.0.2",
    "jest-transform-stub": "^1.0.0",
    "jsdom": "^12.2.0",
    "node-sass": "^4.9.3",
    "sass-loader": "^7.1.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.2",
    "vue-jest": "^3.0.0",
    "vue-template-compiler": "^2.5.17"
  }

有人有什么想法吗?

0 个答案:

没有答案