最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何使Jest记录整个错误对象?

运维笔记admin9浏览0评论

如何使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][Object]

回答如下:

我认为这不是一个玩笑,而是一个普通的nodeJS记录问题。可以使用以下方法解决:

const util = require('util')
console.log(util.inspect(myObject, {showHidden: false, depth: null}))
发布评论

评论列表(0)

  1. 暂无评论