How to use jest with webpack?

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

    It has been 5 years since this question asked, yet its still very confusing for me, I can't believe that its so hard to make jest and webpack works, until I tried this:

    Add babel-jest and babel preset:

    yarn add --dev babel-jest @babel/preset-env
    

    Add babel config:

    // babel.config.js
    module.exports = {
      presets: ["@babel/preset-env"]
    };
    

    This may or may not work for you, since the question title only refers to jest and webpack, people may stumble upon this article just like me that's clueless how to make jest works with webpack, and I hope at least my answer helped them if this doesn't help you.

提交回复
热议问题