Opt-out of truncation for custom classes?
See original GitHub issueThe https://github.com/astorije/chai-immutable plugin extends lots of core assertions to work with ImmutableJS.
The collections in Immutable all have a custom toString()
and inspect()
method which produces a readable version of their internal datastructures. This gets picked up correctly by chai’s inspect
util.
However, if this representation goes over the truncateThreshold
, they are detected as objects and their first two properties are displayed instead - which isn’t useful for these collections.
To work around this, many of the assertion methods convert the objects to a string before passing to the message formatting. This mostly works but it’s easy to miss cases.
This problem should apply to any object with a custom inspect, would it be possible to tweak this behaviour somehow?
Some options I can think of would be to change the object detection to check for plain objects only, or to skip truncation for objects with a custom inspect() method, or to truncate the result of inspect() when objects have an inspect().
Any thoughts?
Two options I can think of
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
Immutable objects have
.inspect()
as an alias for.toString()
, as far as I can tell this is what chai and/or loupe would pick: https://github.com/chaijs/chai/blob/master/lib/chai/utils/inspect.js#L45 https://github.com/chaijs/loupe/blob/master/lib/loupe.js#L61On a related note, you may find https://github.com/Xotic750/inspect-x interesting, it’s also originally based on Node’s inspect and does a good job of handling the newer ES6 datatypes.
👍 from me on this, assuming you mean the result of the
inspect
util (andloupe
in future). that would solve my immediate problem and should work well in general. Would you still want to handle values that were originally strings differently?I think it’s reasonably fair to say it’s a de-facto standard in Node-land, thanks to https://nodejs.org/dist/latest-v4.x/docs/api/util.html#util_custom_inspect_function_on_objects having been in the docs since at least 0.4 that I know of. Whether that’s a good enough reason to lean more heavily on it, I don’t know.
That seems sensible, please let me know if there’s anything on there that I could help contribute with.