How to use jest with webpack?

前端 未结 12 2563
抹茶落季
抹茶落季 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:53

    I think a less hacky solution would be to wrap your preprocessor in a conditional on the filename matching a javascript file:

    if (filename.match(/\.jsx?$/)) {
        return babelJest.process(src, filename);
    } else {
        return '';
    }
    

    This works even if you don't explicitly set the extension in the require line and doesn't require a regex substitution on the source.

提交回复
热议问题