嘲笑模块导出功能

时间:2018-09-13 12:08:13

标签: typescript jestjs

我有一个文件lib.ts

export const getValue() { return 'original value'; }

export const callGetValue() { return getValue(); }

还有一个测试文件lib.spec.ts

import * as lib from './lib';

// ...
    it('works', () => {
        jest.spyOn(lib, 'getValue').mockImplementation( () => 'new value');
        expect(lib.callGetValue()).toBe('new value'); // it's not!
    });
// ...

我想模拟getValue(),并使其返回'new value'。不是。为什么?!

1 个答案:

答案 0 :(得分:1)

很遗憾,这实际上是不可能的,请参见https://github.com/facebook/jest/issues/936

中的讨论
相关问题