-
Notifications
You must be signed in to change notification settings - Fork 668
Allow custom attribute in the Wrapper.find options object. #677
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
Comments
I think this feature is resolved by using the CSS attribute selector. const TestComponent = {
template: '<div>{{ foo }}<child-component foo="bar" /></div>',
}
const wrapper = shallowMount(TestComponent)
expect(wrapper.find('[foo="bar"]').html()).to.equal('<child-component foo="bar"></child-component>') |
When you use a CSS selector it doesn't return the same thing: test('find component', () => {
const wrapper = mount(Component)
expect(wrapper.find(ChildComponent).props()).toMatchSnapshot() // returns VueWrapper instance
})
// gives error: [vue-test-utils]: wrapper.props() must be called on a Vue instance
test('find with css', () => {
const wrapper = mount(Component)
expect(wrapper.find('[attribute="value"]').props()).toMatchSnapshot() // returns Wrapper instance
}) |
You can get the first Wrapper object. https://vue-test-utils.vuejs.org/api/wrapper-array/#at-index You can use filter method. https://vue-test-utils.vuejs.org/api/wrapper-array/#filter-predicate I think that it is unnecessary to add this feature. |
I still think the proposed API would be much nicer, even if it isn't strictly necessary: expect(wrapper.find({ 'key': 'value' }).props()).toMatchSnapshot();
// vs
expect(
wrapper
.findAll(ComponentName)
.filter(w => w.attributes().['key'] === 'value')
.at(0)
.props()
).toMatchSnapshot(); |
Adding more functionality to |
I'd also say using the CSS attribute selector is a better solution, since it's the standard way of performing this queries – also we avoid introducing additional unnecessary complexity to VTU 👍 |
Going to close this one for now. Thanks for the proposal but unfortunately this feature won't be added at this point. |
What problem does this feature solve?
This would allow the tester to access the Wrapper instance of a child component using a custom attribute query.
Consider the following template.
I can use
wrapper.find({ ref })
to access the Wrapper instance of a specific<custom-component>
. If instead I have some other custom attribute that is already in use in conjunction with another testing framework, I have no way to access the Wrapper instance of a specific component.Consider instead this template:
It would be nice if I could do something like
wrapper.find({ selenium: '1' })
to get the Wrapper instance of the first<custom-component>
.What does the proposed API look like?
wrapper.find({ 'custom-attribute-name': 'custom atrribute value' });
The text was updated successfully, but these errors were encountered: