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.

Problems with `hasAttr()`

See original GitHub issue

Hi, 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:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eddyerburghcommented, Aug 8, 2017

Yeah I agree ☺

I’ll add these methods this week and release in 4.0.0

0reactions
eddyerburghcommented, Aug 8, 2017

I thought it should be the prop value of a vue instance

Read more comments on GitHub >

github_iconTop 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 >

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