Import code breaking breaks Jest tests

I use the code splitting function in webpack, but it seems like the joke doesn't recognize the function import():

        import('myModule').then(function (myModule) {
        ^^^^^^
SyntaxError: Unexpected token import

I do not have a special setting. My npm test script just runs jest"test": "jest"

How can I make it work?

I am using the latest version of jest 20.0.4 and babel-jest 20.0.3

+1
source share
1 answer

Oh, I just found the answer.

Just install this plugin: https://github.com/airbnb/babel-plugin-dynamic-import-node and add it to the file .babelrc:

{
  ...
  "env": {
    "test": {
      "plugins": ["dynamic-import-node"]
    }
  }
}
+2
source

Source: https://habr.com/ru/post/1681159/


All Articles