Vue-test-utils: hasAttribute

Created on 24 Aug 2017  ·  6Comments  ·  Source: vuejs/vue-test-utils

Currently hasAttribute checks for DOM attributes. It doesn't check for $attrs.

I can see this causing confusion.

Should There be a separate hasAttrs method?

Should hasAttribute check $attrs if the wrapper is a component wrapper?

Most helpful comment

I'm not sure what the best solution is here, but I definitely vote against seperate hasAttribute and hasAttrs methods that do different things.

All 6 comments

I'm not sure what the best solution is here, but I definitely vote against seperate hasAttribute and hasAttrs methods that do different things.

I'm totally sure I understand what $attrs is, but it sounds like it is just a convenience method/object. In which case I would expect that that anything that this automates is also handled automatically on the opposite side. I.e. according to first google link these are the attributes of the component, in which case I would expect hasAttributes to return also check these. (and hasListeners to also check $listeners)

Isn't it weird that while the docs say

This allows a wrapper component to be created that simply passes all attributes and listeners down to the child.

The attributes and listeners of the child don't contain these objects and/or this repo doesn't check for them?

As far as I understand Wrapper is a combination of accessors to DOM and Vue instance, when it was about 'getProps', 'getData' there is no intersection with DOM node interface (it terms of terms)

Having both doesn't sound like as a good solution, at least there are some reasons to do it

I see that a lot of DOM accessors were added to Wrapper. Was made an assumption that for developers it's handy to have DOM accessors shortcuts. I support it ;-)

So, my proposal is to keep hasAttribute as is and provide shortcut accessor to $attrs only if community would constantly push for that

Should hasAttribute check $attrs if the wrapper is a component wrapper?

It may confuse a lot, from another side it's a classic OOP behaviour, I'm not quite well familiar with differences between wrapper and component wrapper to go deeper here

Although looking at this closer it feels that bulk passing of attributes and listeners from the parent to the child is not a great pattern, so maybe this shouldn't be support at all.

Could always call it .has$attrs().

I'm going to close this issue as there seems to be no more discussion. Happy to reopen if people want to start the discussion back up

Was this page helpful?
0 / 5 - 0 ratings