Marcos Pereira
Marcos Pereira

Reputation: 1176

How to make Jest log the entire error object?

Jest is shortening error logs in the following way:

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] }
    }
]

How can I force it to print the entire error instead of using [Array] and [Object]?

Upvotes: 7

Views: 4819

Answers (2)

Gomino
Gomino

Reputation: 12347

Thank to @andreas answer I was able to add this to my jest.setup.js file:

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

Upvotes: 5

Andreas Köberle
Andreas Köberle

Reputation: 110932

I would assume it is not a jest but a normal nodeJS logging issue. Can be solved by using:

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

Upvotes: 6

Related Questions