Problems with `hasAttr()`
See original GitHub issueHi, I have been recently writing unit tests using avoriaz. There were a few problems with hasAttr()
, for example:
var wrapper = mount(VueComponent)
// I'd like to check if `wrapper` has an attribute called `some-attr`,
// and don't care about what its value is.
expect(wrapper.hasAttr('some-attr')).toBe(true)
// But avoriaz requries a second argument:
// => Error: wrapper.hasAttribute() must be passed value as a string
// If the attribute value is variable then `hasAttr()` is likely to be unusable.
Further more, hasAttr()
is not ideal for error report:
var wrapper = mount(VueComponent)
expect(wrapper.hasAttr('some-attr', 'some-value')).toBe(true)
// If the actual value is something other than expected,
// then the error message gives no idea about what actually happens:
// => Error: Expected false to be true.
I think it would make debugging much easier if the API looks like this:
var wrapper = mount(VueComponent)
// Checks for existence of the attribute:
expect(wrapper.hasAttr('some-attr')).toBe(true)
// Checks for value identity:
expect(wrapper.getAttr('some-attr')).toBe('some-value')
// If the actual value is not as expected, then the error message maybe look like this:
// => Error: Expected 'not-some-value' to be 'some-value'.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
hasattr() – A Dangerous Misnomer - Hynek Schlawack
hasattr() is not faster than getattr() since it goes through the exactly same lookup process and then throws away the result . Why?...
Read more >hasattr returns attribute error even after exception is captured
First, hasattr returns True if the attribute is there, False if it isn't. It only raises an exception if there's a typo in...
Read more >Python hasattr() method - GeeksforGeeks
Python hasattr() function is an inbuilt utility function, which is used to check if an object has the given named attribute and return...
Read more >Python 2 vs 3 hasattr() behaviour | by Wahome - Medium
In python 3, hasattr() catches AttributeErrors only then returns False. All other exceptions bubble up the call stack. It's thus a much more...
Read more >Solved: hasattr(layer, "dataSource") gives error - Esri Community
Hi,. I am trying to iterate over all layers in a map to see the datasources, and as it is recommended it is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah I agree ☺
I’ll add these methods this week and release in 4.0.0
I thought it should be the prop value of a vue instance