【问题标题】:How to make Jest log the entire error object?如何让 Jest 记录整个错误对象?
【发布时间】:2020-03-03 03:08:36
【问题描述】:

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]

【问题讨论】:

    标签: javascript node.js jestjs


    【解决方案1】:

    我认为这不是开玩笑,而是正常的 nodeJS 日志记录问题。可以通过以下方式解决:

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

    【讨论】:

      【解决方案2】:

      感谢@andreas 的回答,我能够将其添加到我的 jest.setup.js 文件中:

      var util = require('util');
      util.inspect.defaultOptions.depth = null; //enable full object reproting in console.log
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-05-13
        • 2017-06-18
        • 2021-12-23
        • 2019-07-12
        • 2021-12-31
        • 2015-07-20
        • 1970-01-01
        相关资源
        最近更新 更多