Jestjs “开玩笑的错误”;transformIgnorePatterns不起作用”;

Jestjs “开玩笑的错误”;transformIgnorePatterns不起作用”;,jestjs,Jestjs,我正在使用Jest测试框架为我的JavaScript/React JS应用程序编写单元测试。当我运行测试时,我得到以下错误 ● Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

我正在使用Jest测试框架为我的JavaScript/React JS应用程序编写单元测试。当我运行测试时,我得到以下错误

  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    C:\Users\{user}\{project}\app\node_modules\react-date-picker\node_modules\react-calendar\dist\Calendar.css:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){.react-calendar {
这是“npm运行单元:测试”的命令


当我再次运行测试时,仍然会出现相同的错误。如何修复它?

这里有一个非常类似的例子,除了设置
transformIgnorePatterns
之外,他还通过向每个
lib/app
编译器选项添加
allowJs:true
(或者根
tsconfig.json
)来修复它


请参阅来源:

您能告诉我如何配置该文件tsconfig.json吗?我补充说,该文件似乎不起作用,因为该文件似乎没有被拿起。对不起,我将无法及时做到这一点。
const esModules = [ 'react-date-picker'].join('|');
module.exports = {
    verbose: true,
    transformIgnorePatterns: [`/node_modules/(?!${esModules})`]
};
"jest --watchAll --testPathPattern=tests/unit --config jest.config.js",