Code splitting `import` breaks Jest tests

前端 未结 1 962
梦毁少年i
梦毁少年i 2021-01-05 06:26

I\'m using the code splitting feature of webpack, but it seems that jest doesn\'t recognize the import() function:

        import(\'myModule\').         


        
相关标签:
1条回答
  • 2021-01-05 07:21

    Oh I just found the answer.

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

    {
      ...
      "env": {
        "test": {
          "plugins": ["dynamic-import-node"]
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题