How can I mock Webpack's require.context in Jest?

前端 未结 8 802
执念已碎
执念已碎 2020-12-08 09:38

Suppose I have the following module:

var modulesReq = require.context(\'.\', false, /\\.js$/);
modulesReq.keys().forEach(function(module) {
  modulesReq(modu         


        
8条回答
  •  生来不讨喜
    2020-12-08 10:14

    Installing

    babel-plugin-transform-require-context

    package and adding the plugin in the .babelrc resolved the issue for me. Refer to the documentation here: https://www.npmjs.com/package/babel-plugin-transform-require-context

提交回复
热议问题