How to use jest with webpack?

前端 未结 12 2581
抹茶落季
抹茶落季 2020-12-08 06:00

I use webpack to develop a React component. Here is a simple version of it:

\'use strict\';

require(\'./MyComponent.less\');

var React = require(\'react\')         


        
12条回答
  •  隐瞒了意图╮
    2020-12-08 06:58

    Webpack is a great tool, but I don't need to test it's behavior with my Jest unit tests, and adding a webpack build prior to running unit tests is only going to slow down the process. The text-book answer is to mock non-code dependencies using the "moduleNameMapper" option

    https://facebook.github.io/jest/docs/webpack.html#handling-static-assets

提交回复
热议问题