【问题标题】:jest.config is being ignoredjest.config 被忽略
【发布时间】:2022-05-09 20:25:44
【问题描述】:

我的 jest.config.js 中有以下内容

module.exports = {
    preset: 'ts-jest/presets/js-with-ts',
    testEnvironment: 'jsdom'
};

但是当我运行 npm test 时它被忽略了。有人可以帮忙吗?

这是我的 package.json

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

【问题讨论】:

    标签: reactjs jestjs


    【解决方案1】:

    好像加上-- --config=jest.config.js就够了。

    您可以尝试将 package.json 中的脚本“test”替换为 react-scripts test -- --config=jest.config.js,否则您可以将 jest 配置直接设置到 package.json 中

    你可以在这里找到答案:How to use jest.config.js with create-react-app

    【讨论】:

      【解决方案2】:

      请记住,您可能会覆盖默认值,因此您需要按照文档Jest Documentation scroll to defaults 中的说明进行要求

      仅仅制作一个 module.exports 是不够的。

      【讨论】:

        猜你喜欢
        • 2021-06-04
        • 2022-10-02
        • 1970-01-01
        • 1970-01-01
        • 2016-09-26
        • 2016-06-05
        • 2014-02-25
        • 2011-05-09
        • 2015-02-08
        相关资源
        最近更新 更多