question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't print array enumerable properties via inspect by default

See original GitHub issue

The Problem

When using a library that modifies the array prototype, the expected [ ] to deeply equal [ ] becomes very noisy.

Here is a screenshot of this issue while using Ember:

image

Notice how small the vertical scroll thumb is.

I also created a minimum viable example as a gist.

The History

I then began to dig into why this ever came to be this way because it doesn’t seem useful to me. This led me to #120, #125, and https://github.com/chaijs/chai/commit/f76eedd46f282e0c948f0c9ad76221e9ae7d53b6

The tl;dr of those issues is inspect was originally borrowed from node, which does not print enumerable properties on arrays. This feature was added partly in support of .eql support for DOM nodes and matching that support when printing. This is reasonable since something like AssertionError: expected [ ] to deeply equal [ ] would lead to confusion.

The Proposal

I suggest that printing enumerable properties is an optional behavior just like show hidden is.

This way the more common case of plain arrays with modified prototypes get printed properly, and in cases where the enumerable properties are relevant, inspect can be invoked with the showEnumerable flag.

I think the only point of contention here is whether or not it’s safe to assume that whenever enumerable properties should be printed, an addon is preferred over a primitive assertion like .eql.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
keithamuscommented, May 11, 2016

There’s a sort of unwritten plan to refactor our inspection lib - loupe - and make it much more intelligent. It’s on my todo list after refactoring deep-eql (which will likely, hopefully, be this week). After the refactor this kind of issue will likely no longer be present - as our error messages will (hopefully) prioritise showing the different values of the two objects.

1reaction
lucasfcostacommented, May 11, 2016

@meeber nice catch. IMO we could hide that kind of property for the members assertion, since it’s not taken into account we would have no problems showing a reduced part of the current output.

I was thinking about a flag which is config value, not an assertion chain, I’m sorry, I should’ve expressed myself better. Maybe comparePrototypeProps would be a clear name for it, but feel free to suggest other options, anyway, I feel like this won’t be needed at all after reading @keithamus’ post.

Since he has a nice solution for this I think we should wait for that refactor before moving on to more changes on top of this behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to get the non-enumerable inherited property ...
Your question answered the question I was going to ask: How to inspect non-enumerable properties (just to explore what is available in ...
Read more >
Object.prototype.propertyIsEnumerable() - JavaScript | MDN
The propertyIsEnumerable() method returns a boolean indicating whether the specified property is the object's enumerable own property.
Read more >
What does enumerable property mean in JavaScript?
An enumerable property in JavaScript means that a property can be viewed if it is iterated using the for…in loop or Object.keys() method....
Read more >
View the properties of DOM objects - Chrome Developers
By default, the Properties pane doesn't show properties with null and undefined values. To see all properties, check Show all.
Read more >
Enumerability of properties • Deep JavaScript - Exploring JS
If you aren't, check out §9 “Property attributes: an introduction”. 12.1 How enumerability affects property-iterating constructs #. To demonstrate how various ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found