2

I am using React in Ruby project with react_on_rails gem Everything is ok, but when I start Jest test this error appears:

/Users/alexandar/projects/ezeewallet.com/app/javascript/bundles/DatePicker/DatePickerRange.jsx:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import PropTypes from 'prop-types';
                                                                                                     ^^^^^^^^^

    SyntaxError: Unexpected identifier

      at new Script (vm.js:80:7)
      at Object.<anonymous> (spec/javascripts/member/DatePicker.spec.js:15:24)

package.json:

"devDependencies": {
    "add": "^2.0.6",
    "babel-core": "^6.26.3",
    "babel-eslint": "^8.0.2",
    "babel-jest": "^23.6.0",
    "babel-plugin-module-resolver": "^3.0.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "clean-webpack-plugin": "^1.0.0",

  },
   ....

.babelcr:

{
  "presets": [["env", {"modules": false}], "react"],
  "env": {
    "test": {
      "presets": [["env"], "react"]
    }
  },
  "plugins": [
    ["module-resolver", {"root": ["./app/javascript"], "alias": {}}],
    "syntax-dynamic-import",
    "transform-object-rest-spread",
    ["transform-class-properties", {"spec": true}]
  ]
}

Am I missing something?

Regards, Alex

1
  • Iv forgotten to add x for jsx files in package json: "jest": { "transform": { "^.+\\.jsx?$": "babel-jest" } Commented Dec 13, 2018 at 10:38

1 Answer 1

2

Iv forgotten to add x for jsx files in package json:

"jest": { "transform": { "^.+\\.jsx?$": "babel-jest" }

Now everything is fine

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.