-
Notifications
You must be signed in to change notification settings - Fork 668
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
Add support for getting prop, classes and attributes by key #941
Conversation
Thanks for this, I've been intending to add it for a while! Could you also update |
Sure! |
Great :)
|
@eddyerburgh and what should the return value for |
@eddyerburgh I assumed I successfully used function overloading for the Thanks! |
docs/api/wrapper/attributes.md
Outdated
@@ -13,3 +13,11 @@ import Foo from './Foo.vue' | |||
const wrapper = mount(Foo) | |||
expect(wrapper.attributes().id).toBe('foo') | |||
``` | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just move the assertion to the above example, no need to duplicate the set up.
eg:
import { mount } from '@vue/test-utils'
import Foo from './Foo.vue' import Foo from './Foo.vue'
const wrapper = mount(Foo) const wrapper = mount(Foo)
expect(wrapper.attributes().id).toBe('foo')
expect(wrapper.attributes('id')).toBe('foo')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the rest of the docs pages
packages/test-utils/src/wrapper.js
Outdated
@@ -112,9 +115,17 @@ export default class Wrapper implements BaseWrapper { | |||
} | |||
}) | |||
classes = classes.map( | |||
className => cssModuleIdentifiers[className] || className | |||
klass => cssModuleIdentifiers[klass] || klass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the name change? Can you replace it with c
rather than klass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
className
ended up shadowing the argument name so I ended up changing it here since it isn't user facing. I am not sure you can use class
since it is a reserved word. How about name
?
packages/test-utils/src/wrapper.js
Outdated
@@ -766,7 +784,8 @@ export default class Wrapper implements BaseWrapper { | |||
*/ | |||
setSelected (): void { | |||
const tagName = this.element.tagName | |||
const type = this.attributes().type | |||
const attributes = this.attributes() | |||
const type = typeof attributes === 'object' ? attributes.type : '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this to fix flow errors? If so you can just add // $FlowIgnore
above the original line. We know it's never going to return a string, so there's no need to guard against it.
We're actually going to replace flow with TypeScript soon, which would fix this issue. It's better to add flow ignores now rather than add extra code to satisfy flow.
@eddyerburgh Thanks for the feedback. It should all be addressed. |
Sorry there was another comment that I thought I'd added—can you add an |
… key Signed-off-by: Will Soto <will.soto9@gmail.com>
@eddyerburgh done and rebased 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this :)
Matches a similar interface from Enzyme:
Just a tiny bit of syntactic sugar to make getting a particular prop easier.
NB: I didn't see an issue for this when I looked, but will be happy to make one if it's necessary.