Does Jest support ES6 import/export?

后端 未结 7 784
情话喂你
情话喂你 2020-11-29 01:21

If I use import/export from ES6 then all my Jest tests fail with error:

Unexpected reserved word

I convert my object un

相关标签:
7条回答
  • 2020-11-29 01:46

    For an updated configuration, I'm using https://babeljs.io/setup#installation

    Select JEST and be happy:

    As a reference, the current configuration:

    npm install --save-dev babel-jest
    

    In your package.json file, make the following changes:

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

    Install babel preset:

    npm install @babel/preset-env --save-dev
    

    Create a .babelrc file:

    {
      "presets": ["@babel/preset-env"]
    }
    

    Run your tests:

    npm run test
    
    0 讨论(0)
提交回复
热议问题