tj / should.js

BDD style assertions for node.js -- test framework agnostic
MIT License
2.75k stars 194 forks source link

Allow control over the depth of messages when comparing deep objects #130

Closed erelsgl closed 11 years ago

erelsgl commented 11 years ago

I compared to deep objects with should.eql, and got the following message: expected

{ classes: [ '{"Greet":true}' ], explanation: [ 'hi', [ 'depth=1: Greet', [Object], 'depth=2: true', [Object] ] ] }

to equal

{ classes: [ '{"Greet":true}' ], explanation: [ 'hi', [ 'depth=1: Greet', [Object], 'depth=2: true', [Object] ] ] }

Probably, the difference is within the [Object], but it is not seen. I think there should be a way to control the depth of objects that are displayed in such messages.

btd commented 11 years ago

In should.js we are using util.inspect function to show objects, but it is bad we do not expose it to public. Probably we should. For now I only can suggest two workarounds:

  1. to patch util.inspect to have default object depth increased (i know it is bit weird).
  2. Define for inspected object .inspect method and call in this method util.inspect with required options.

In next release i will add inspect function to exported object.

btd commented 11 years ago

Reproduced. It is important that it is happen outside test runner. In v2 I expose inspect as should.inspect.

erelsgl commented 11 years ago

OK, thanks.