找不到模块' store / actions / user'来自' login-form.js'

时间:2018-02-21 16:32:57

标签: reactjs react-redux jest

我有 jest 配置

"jest": {
    "transform": {
      "^.+\\.jsx?$": "babel-jest",
      ".*": "./tests/preprocessor.js"
    },
    "moduleFileExtensions": [
      "js",
      "jsx",
      "json"
    ],
    "setupFiles": [
      "./tests/enzyme_setup"
    ],
    "moduleDirectories": [
      "node_modules",
      "bower_components",
      "shared"
    ]
  }

我正在使用react redux,我收到了这个错误:

测试套件无法运行

Cannot find module 'store/actions/user' from 'login-form.js'

  2 | import * as PropTypes from 'prop-types';
  3 |
> 4 | import { userActionsShape } from 'store/actions/user';
  5 | import Scss from './scss/index.scss'
  6 |
  7 | export class LoginFormComponent extends React.Component {

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:194:17)
  at Object.<anonymous> (src/app/components/auth/login-form/login-form.js:4:13)
有人可以帮帮我吗? 我坚持这个

2 个答案:

答案 0 :(得分:0)

test()

npm install --save --dev jest-css-modules-transform 这个对我有用 非常感谢Carlos Vieira

答案 1 :(得分:0)

我已经解决了 我把这个配置开玩笑

{
    "transform": {
      "^.+\\.js$": "babel-jest",

      "^.+\\.jsx$": "<rootDir>/__tests__/enzyme_setup.js",
      "^.+\\.scss$": "jest-css-modules-transform"
    },
    "moduleFileExtensions": [
      "js",
      "jsx",
      "json",
      "node",
      "scss"
    ],
    "setupFiles": [
      "./__tests__/enzyme_setup"
    ],
    "moduleDirectories": [
      "node_modules",
      "bower_components",
      "shared"
    ],
    "moduleNameMapper": {
      "\\.(css|less)$": "identity-obj-proxy",
      "^store/actions/user$": "<rootDir>/src/app/components/auth/login-form/index.js",
      "^models/user$": "<rootDir>/src/app/components/user/user-info/index.js",
      "^store$": "<rootDir>/src/app/store/index.js",
      "^initial-state$": "<rootDir>/src/app/store/initial-state.js"
    },
    "testRegex": "/__tests__/.*.test.(js|ts|tsx)?$"
  }

完成! 这个对我有用 非常感谢 卡洛斯·维埃拉