jest: Test suite failed to run, SyntaxError: Unexpected token import

前端 未结 6 1744
粉色の甜心
粉色の甜心 2020-12-01 20:44

This is my jest configuration from the package.json file:

\"jest\": {
    \"automock\": false,
    \"browser\": true,
    \"moduleNameMapper\": {
      \"\\\         


        
6条回答
  •  情话喂你
    2020-12-01 21:08

    Jest doesn't handle imports so it needs a transform plugin, and this is why I had to add the plugin:

    babel-plugin-dynamic-import-node

    and update my babel settings to tell jest to use this plugin to transform the code properly:

    "env": {
        "test": {
          "plugins" : ["dynamic-import-node"]
        }
      }
    

    GitHub thread

提交回复
热议问题