-
Notifications
You must be signed in to change notification settings - Fork 668
How to check an element is displayed (v-show) ? #327
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
From the Vue.js docs,
Here is an example: <template>
<button v-show="false" />
</template>
I think this kind of q and a is best for stackoverflow, though. Does that help? Edit: I just realized you are looking at children elements of |
I understand, but I can't find It's more a feature request than a Q&A, as a (new) user of vue-test-utils, I just expect to find a |
Here's a possible implementation (Working with JEST/JSDOM) : function isVisible(wrapper: Wrapper<Vue>) {
const computedStyle = window.getComputedStyle(wrapper.element)
return computedStyle.display !== 'none'
} May I open a pull request that adds a |
There are other use cases that are hard to solve related to
It would be nice to have a |
I can see a use case for expect(wrapper.findAll('.item').at(3).displayed()).toBeTruthy() is much less readable than expect(wrapper.find('.modelAttrB').displayed()).toBeTruthy() I think Also, this is related to #331 , if we remove |
I wrote a simple example on top of this issue, but in real life i'm writing tests for a Tree component. In the tree view, the tree node holding |
Hey I think this is a great idea. One way I can think of implementing it would be to walk up the DOM tree with I agree with @lmiller1990 . Would you like to look into implementing this @Toilal ? @lmiller1990 We can still check style by accessing the wrapper element: wrapper.element.style.visibility // hidden |
I'll try to implement this during the week-end |
@eddyerburgh I try to implement this, but my first unit test fails :( I can't find a way to retrieve parent of a VNode. It seems to be always null. (See #328) parent (): Wrapper | ErrorWrapper {
const parentVNode = this.vnode.parent
if (parentVNode) {
return createWrapper(parentVNode, this.update, this.options)
}
return new ErrorWrapper('No parent found')
} describe('parent', () => {
it('returns parent element', () => {
const compiled = compileToFunctions('<div class="parent"><div class="child"></div></div>')
const wrapper = mount(compiled)
const child = wrapper.find('.child')
expect(child.parent().classes()).to.include('parent')
})
}) |
This will be released in beta.11 |
@Toilal Just for completion, you may ment |
Focus |
I try to assert that elements are displayed or not. Those elements are children (or even grand-children) of a v-show node.
Consider the following, I wish to assert display of
.item
elements.It seems a common use case, but I can't find any way in vue-test-utils to do that. I can't rely on DOM element properties as I run tests with JEST (JSDOM doesn't layout elements and can't tell if an element is displayed neither). Maybe there's something possible with VueJS VNode API ?
I would expect some kind of
displayed
method in the Wrapper API.The text was updated successfully, but these errors were encountered: