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]
?
Answer: Use console. log() or JSON. stringify() Method This method will print the object in browser console.
Jest by default prints all console. log (warnings, errors, etc) messages to the console. That's great - it helps you understand what's going on in your code when tests run.
If using Jest test framework, you can turn off all console messages by one command: jest --silent .
Logging objects in Node. jslog() into a JavaScript program that runs in the browser, that is going to create a nice entry in the Browser Console: Once you click the arrow, the log is expanded, and you can clearly see the object properties: In Node, the same happens.
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}))
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With