gpt4 book ai didi

javascript - 在这次测试之外会看到这个月亮吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:55:20 27 4
gpt4 key购买 nike

我看到一个测试在 describe block 之外有一个 jest.mock 调用。

我担心这会导致在测试之外可见的变化。我不希望此测试影响其他测试。

应该将 jest.mock 移到 describe block 内还是按原样移动?

import target from '../';

jest.mock('../../../helpers/helpers.api', () => ({
httpPost(...args) {
return args;
}
}));

describe('my component', () => {
it('should foo', () => {
//...
});
});

最佳答案

据我了解,您的示例没有问题。

Modules that are mocked with jest.mock are mocked only for the file that calls jest.mock. Another file that imports the module will get the original implementation even if run after the test file that mocks the module.

https://facebook.github.io/jest/docs/en/jest-object.html#jestmockmodulename-factory-options

关于javascript - 在这次测试之外会看到这个月亮吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46280395/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com