Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove outerHTML fallback from inspect #840

Closed
wants to merge 4 commits into from
Closed

Remove outerHTML fallback from inspect #840

wants to merge 4 commits into from

Conversation

shvaikalesh
Copy link
Contributor

@shvaikalesh shvaikalesh commented Oct 10, 2016

Supersedes #829. We still need to do some work with inspect (according to extremely useful #457 👍 ) though: it seems we can use Node's util.inspect for every type expect for HTMLElement. Is anyone working on loupe or inspect atm or I can help?

var isDOMElement = function (object) {
if (typeof HTMLElement === 'object') {
function isDOMElement(object) {
if (typeof HTMLElement !== 'undefined') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of Custom Elements V1, HTMLElement is reported as function in newest Chrome and Firefox.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if HTMLElement is undefined?
The MDN docs aren't very clear about which browsers support this or not, there's a lot of ? on the compatibility table.

@meeber
Copy link
Contributor

meeber commented Oct 10, 2016

LGTM (and I appreciate separate commits for each distinct change being made).

@lucasfcosta
Copy link
Member

Hi @shvaikalesh, thanks for the work! This seems awesome (as it always does on your PRs) 😄

Since the outerHTML prop is supported since FF 11 and IE 4 (according to MDN) I totally agree with that change.

Regarding the checks for the HTMLElement, I'm not sure we should totally remove that. I've taken a look at the MDN page for those and it isn't clear which browsers support it and which don't. However, if you have any more info on this I'd be happy to learn about it 😄

Also, is there any special reason for us to be using those additional checks for isArray? It has been supported for a long long time and we still have those checks, but I can't think of any special cases that makes those additional checks useful. If you guys do, please tell me, otherwise I agree with this change too.

@shvaikalesh
Copy link
Contributor Author

shvaikalesh commented Oct 10, 2016

@lucasfcosta HTMLElement and many other DOM interfaces were not available in IE8, but work fine in IE9 (SauceLabs).

Doing

Array.isArray(obj) || toString.call(obj) === '[object Array]'

is kinda dangerous, it gives false positive for { [Symbol.toStringTag]: 'Array' }.
Maybe it is ponyfill (for IE8) done wrong, or support for Object.create([]) (which is confusing)

@lucasfcosta
Copy link
Member

@shvaikalesh thanks for the explanation, it looks clear to me now! So, if HTMLElement is supported on every browser after IE8 I think we can use only object instanceof HTMLElement when checking if something is a DOM element (instead of also checking if typeof HTMLElement !== 'undefined'), because as #124 says, we don't support <= IE 8. What do you think?

Also, I feel like Object.create([]) should be supported, but I'm not sure about it, I think that if someone is using the Array prototype for another object, the user expects it to be treated like an array. What do you guys think?

Also, thanks again for this work, it's looking great! I'm impressed by your knowledge about browser supports 😄

@shvaikalesh
Copy link
Contributor Author

shvaikalesh commented Oct 11, 2016

We need typeof HTMLElement !== 'undefined' for Node.js.

Displaying Object.create([]) as [] leads to a confusion, because former does not have internal [[DefineOwnProperty]] method, thus have no special behavior for setting indexed keys and .length. If subclass of Array is wanted, extends should be used for correct implementation.

I think util.inspect does pretty good job displaying many types (Map and Set included #662), and we should move towards using it for everything except html elements.

@keithamus
Copy link
Member

We have type-detect for exactly this kind of stuff. If type-detect isn't doing something sufficiently, we should move the convo there.

@lucasfcosta
Copy link
Member

lucasfcosta commented Oct 11, 2016

@shvaikalesh ah, that makes sense!
Also, as @keithamus said, I think we could use type-detect for the array detection in order to keep the behavior consistent across all of the Chai ecosystem.

@meeber
Copy link
Contributor

meeber commented Oct 17, 2016

Based on the discussion, it looks like we just need to switch the isArray check to use type-detect instead, and then we're good to go. The HTMLElement stuff looks correct as-is with feature detection in case of non-browser environment, and instanceof which is identical to how type-detect does it.

@keithamus
Copy link
Member

Hey @shvaikalesh. @lucasfcosta and I are clearing house on all these PRs. We have https://github.com/chaijs/chai/projects/2 which we're going to use to track some features we want, but we're going to significantly refactor all of chai over the next few weeks.

We'll be sure to come back to this. I'll drop you some messages when loupe is in a releasable state and we can make sure inspection of HTML entities works in a robust way.

@keithamus keithamus closed this Jun 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants