-
Notifications
You must be signed in to change notification settings - Fork 667
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
Method that return parent #65
Comments
I would prefer to keep the API small. This would require adding a I'd like hear what other people think 🙂 |
I agree @eddyerburgh. Initial thoughts are that this would add a fair amount of complexity and create some ambiguity on whether it is the parent vue component or parent html node. |
I'm closing this as we don't intend to implement this at the moment |
Since #337 would help in this case. |
This feature request is for a parent method for a vnode, not a Vue instance. You wouldn't be able to access a vnode parent, the only way would be to add a parent property to each vnode inside vue-test-utils. |
Is there any recommended workaround to access the parent? |
@anorborg Here's my workaround, fwiw:
Use caseI have a event calendar component that is a week or month calendar, and I'm testing that the event fixture from the tests and the link to go to the route for just that calendar day match. The markup looks like this: <li v-for="(day, index) in calendarDays" :key="index" class="day">
<div class="date">{{ day.date.format('DD') }}</div>
<div v-for="(event, index) in eventsOnDay(day.date)" :key="index" class="event"> {{ // stuff }}</div>
<router-link :to="detailPath(day.date)" class="router-link" />
</li> I want to find the it('has links to the detail view', async function() {
const wrapper = await mount(EventCalendar, { localVue, store, router })
const eventWrapper = wrapper.find('.event') // this returns a Wrapper instance
// parentElement is the <li />, then you can use querySelector to find the sibling, so
// detailLink is also an Element instance
const detailLink = eventWrapper.element.parentElement.querySelector('.router-link')
expect(detailLink.getAttribute('href')).toMatch(`/detail/${testEvent.date)}`)
}) |
@lusarz Depending on your needs, you could use: wrapper.find().element.parentElement But if you need the wrapper object of the parent element, it might be possible by using the querySelector, by adding css properties to your HTML elements. |
In one of my test scenario I need to get parent of element, something like:
wrapper.find(selector).parent().hasClass('disabled')
What do you think about adding
parent
method to wrapper ?The text was updated successfully, but these errors were encountered: