【问题标题】:Jest mock not working when any transformer is configuration配置任何变压器时,笑话模拟不起作用
【发布时间】:2022-02-28 06:49:36
【问题描述】:

当向 Jest 配置添加任何转换器或空属性转换时,模拟不起作用。下面是简单的代码。

笑话配置:

"transform": {
any regex: any transformer
}

模块说:

module.exports = (m) => {
    console.log(m);
};

模块测试模块:

const say = require("./say");

module.exports = () => {
    say("Hello world!");
};

测试:

jest.mock("./say", () => () => console.log("Mock!!!!"));

test("any test", () => {
});

如果删除转换配置,模拟工作,将得到消息:模拟!!!!!!。

【问题讨论】:

    标签: mocking jestjs


    【解决方案1】:

    似乎添加转换会删除默认值。

    添加 '.*': 'babel-jest' 作为后备解决了这个问题。

    transform: {
      '\\.xml$': 'jest-raw-loader',
      '.*': 'babel-jest',
    },
    

    相关问题

    【讨论】:

      猜你喜欢
      • 2019-10-15
      • 2020-10-01
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      • 2021-07-03
      • 1970-01-01
      • 2021-01-07
      相关资源
      最近更新 更多