最佳答案
我正在使用 创建-反应-应用程序并尝试编写一个 开玩笑的测试来检查 console.log
的输出。
我的测试功能是:
export const log = logMsg => console.log(logMsg);
我的测试是:
it('console.log the text "hello"', () => {
console.log = jest.fn('hello');
expect(logMsg).toBe('hello');
});
这是我的错误
FAIL src/utils/general.test.js
● console.log the text hello
expect(received).toBe(expected) Expected value to be (using ===): "hello"
Received:
undefined
Difference:
Comparing two different types of values. Expected string but received undefined.