Skip to content
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

isVisible() not seeing display: none using vitest with jsdom #2073

Open
BJSS-russell-pollock opened this issue May 31, 2023 · 4 comments
Open

Comments

@BJSS-russell-pollock
Copy link

Subject of the issue

@vue/test-utils: 2.3.2
jsdom: 22.0.0
vitest: 0.31.0

Using vue3, vue-test-utils and vitest with jsdom - our tests are failing on isVisible().toBeFalsy()

The documentation says the display: none is one method used to identify isVisible()
https://v1.test-utils.vuejs.org/api/wrapper/isvisible.html

The tests were passing using Jest

Steps to reproduce

Mount wrapper

Element when shown
<div class="accordionRow" style="">

await wrapper.find('.accordionHead').trigger('click')
expect(wrapper.find('.accordionRow').isVisible()).toBeTruthy()
Test Passes

Element when hidden
<div class="accordionRow" style="display: none;">

await wrapper.find('.accordionHead').trigger('click')
expect(wrapper.find('.accordionRow').isVisible()).toBeFalsy()
Test Fails

Using

expect(wrapper.find('.accordionRow').attributes('style')).toBe('display: none;')
Test Passes

Expected behaviour

Test should pass when the attribute style is display: none; and .isVisible().toBeFalsy() is used for the assertion

Actual behaviour

Test fails because the assertion is not seeing display: none;

Possible Solution

expect(wrapper.find('.accordionRow').attributes('style')).toBe('display: none;')

@samatt1234
Copy link

Same for me

1 similar comment
@guiguzixl
Copy link

Same for me

@lmiller1990
Copy link
Member

Try using attachTo according to v2 docs: https://test-utils.vuejs.org/api/#isVisible

I don't think something is considered visible or not if it is not in the actual document. I could be wrong though, let me know if that helps.

@ravihlb-cp
Copy link

ravihlb-cp commented Apr 17, 2024

Same for me as well.

I am using attachTo: document.body on the mount call and in my case I can't even use the workaround through .attributes(...) since I'm setting display: none through the style element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants