console.log语句在Jest中不输出任何内容。昨天还挺管用的,今天突然就不管用了。我没有对我的配置做任何更改,也没有安装任何更新。
我没有使用——forceExit选项。仍然看到这个问题。
console.log语句在Jest中不输出任何内容。昨天还挺管用的,今天突然就不管用了。我没有对我的配置做任何更改,也没有安装任何更新。
我没有使用——forceExit选项。仍然看到这个问题。
当前回答
在MacOS的笑话版本26.6.3中,我必须附加——silent="false"
其他回答
在之前的回复中尝试了一些配置选项后,使用console.debug()而不是console.log()可以工作。
在我的例子中,问题是从编译版本(在dist文件夹中)而不是从src文件夹中导入函数。因此它使用的是旧版本。所以重建项目和/或从src导入解决了我的问题。
将我的文件从index.spec.js重命名为index.test.js。
你可以像这样一起运行两个选项——watch——verbose false,如果你还想监视文件并查看输出。
只运行一次就做——冗长的错误
日志记录不能打印的一个潜在原因是console.log被嘲笑了。如下所示
// jest-setup.js
global.console = {
// eslint-disable-next-line no-undef
log: jest.fn(), // console.log are ignored in tests
// log: console.log,
// Keep native behaviour for other methods, use those to print out things in your own tests, not `console.log`
error: console.error,
warn: console.warn,
info: console.info,
debug: console.debug,
};
// package.json
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"setupFilesAfterEnv": [
"@testing-library/jest-native/extend-expect",
"<rootDir>/src/config/jest-setup.js"
],
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.test.{ts,tsx}"
]
},
如果你想禁用console.log,这是常用的