javascript - 如何让 Jest 记录整个错误对象?
问题描述
Jest 通过以下方式缩短错误日志:
GraphQLError {
message: 'Cannot set property \'marketCap\' of undefined',
locations: [ { line: 3, column: 11 } ],
path: [ 'listings' ],
extensions:
{ code: 'INTERNAL_SERVER_ERROR',
exception: { stacktrace: [Array] }
}
} 0 [
GraphQLError {
message: 'Cannot set property \'marketCap\' of undefined',
locations: [ [Object] ],
path: [ 'listings' ],
extensions: { code: 'INTERNAL_SERVER_ERROR', exception: [Object] }
}
]
如何强制它打印整个错误而不是使用[Array]
and [Object]
?
解决方案
我认为这不是开玩笑,而是正常的 nodeJS 日志记录问题。可以通过使用解决:
const util = require('util')
console.log(util.inspect(myObject, {showHidden: false, depth: null}))
推荐阅读
- android - TfLite Android:为多个输出模型运行推理时的垃圾值
- excel - 在 Excel 中更改组合文本和公式的字体颜色
- javascript - 为什么在 multer 中间件之后不考虑我的文件?
- python - 无法使用 python 从 facebook api 获取 facebook 活动历史数据
- c# - 从后面的代码编辑 web.config 中的 httpErrors 部分
- c - ffmpeg中.so文件和java库的区别
- php - 在 php 中更改 $success 消息的颜色
- c++ - Qt 4.7 QFileSystemWatcher 示例
- java - Spring Reactive WebFlux - 如何自定义 BadRequest 错误信息
- webpack - 通过 Webpack babel-loader 添加时,Promise polyfill 在 FireFox 和 IE11 中不起作用