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

Mar*_*ira 5 javascript node.js jestjs

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] }
    }
]
Run Code Online (Sandbox Code Playgroud)

如何强制它打印整个错误而不是使用[Array]and [Object]

And*_*rle 5

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

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


Gom*_*ino 5

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

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