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
toBeVisible should imply toBeInTheDocument #338
Comments
Makes sense. Are you up to contribute this fix? If not I may get to it next week. |
Yep, I can make a PR. One other thing I have a question about:
expect(null).not.toBeInTheDocument() // passes Should expect(null).not.toBeVisible() |
However, I'd say |
Yeah right now |
Patch #339 broke some Vue tests for me. The tests look like this: const wrapper = mount( SomeComponent, {localVue} );
let myInput = wrapper.find( 'input#foo' );
expect( myInput.element ).toBeVisible(); With version 5.11.10 I get "Received element is not visible (element is not in the document)" errors. Using Vue 2.6.11 with @vue/test-utils 1.1.3 |
@gbirke what's Normally this library is used alongside the corresponding testing-library for the frontend framework you use. If you're using Vue, then you'd be using https://github.com/testing-library/vue-testing-library, and if you are, then the way to render a component using that library looks different than in your example. At least according to what is documented in https://github.com/testing-library/vue-testing-library#a-basic-example Can you clarify that before we can discuss this further? |
I re-read your message and deducted that this what you mention as It would help if you created a minimal repo in codesandbox to investigate. |
I have created a minimal setup with If you add Checking for visibility with jest-dom is the recommended way of doing this, accoring to the Vue testing documentation |
Looking at that linked documentation, shouldn't you be using import { mount } from '@vue/test-utils'
import Foo from './Foo.vue'
const wrapper = mount(Foo)
expect(wrapper.isVisible()).toBe(true)
expect(wrapper.find('.is-not-visible').isVisible()).toBe(false) Like I said, it seems that testing library operates in a way that is incompatible with how jest-dom works. jest-dom assumes and expects that the DOM structure being tested is attached to a host |
@gnapse Thank you! I wanted to report an issue, but you're totally right and it worked! |
Quoting from the linked documentation:
That's why I set up the test the way it is. You can raise an issue with For now I'll just stick with version 5.11.9 of jest-dom. If there are important updates to jest-dom I might use the testing library with |
Hi all :) I just discovered testing-library (which is awesome, thanks a lot for that) and was about to report an issue for the case I think this test should pass. Let me give you an exemple (which is a close version of my actual code). I want to code a button that makes a request that may take time, so I want to show a spinner while waiting for the answer. For the moment, my test code looks like this (simplifying the server mocking part because it's not important) : const server = mockServer();
userEvent.click(screen.getByRole("button"));
expect(screen.queryByRole("status")).toBeVisible();
server.answer(200);
expect(screen.queryByRole("status")).not.toBeInTheDocument(); It works fine but it make details that I don't want to bother with explicit. const server = mockServer();
userEvent.click(screen.getByRole("button"));
expect(screen.queryByRole("status")).toBeVisible();
server.answer(200);
expect(screen.queryByRole("status")).not.toBeVisible(); What do you think ? Edit : to avoid a breaking change, maybe introducing a const server = mockServer();
userEvent.click(screen.getByRole("button"));
expect(screen.queryByRole("status")).toBeVisible();
server.answer(200);
expect(screen.queryByRole("status")).toBeInvisible(); |
It sounds like you are suggesting that I think it might make sense to make that change, but it sounds like @gnapse thinks it shouldn't pass |
What I think is not something final. I'm willing to change my mind. One thing I may never be on-board with is to make a I'm hesitant to do this, but not outright opposed, only on the fence. I'd like the opinion of @testing-library/core-maintainers about it. |
In my opinion |
@eps1lon I think I just understood something : Of course, I have my prefered definition :) Before arguing for it, i'd like to be sure I understood you correctly :) |
In testing-library we usually go with "visible" = possibly perceivable + accessible by assistive technology. E.g. This definition also means that inaccessible color combinations, opacity, possible occlusion etc. are considered "visible" since it'd be incredibly hard to implement (and maintain) but also not possible in JSDOM (which is a popular testing environment).
Not every human has the same vision. Not every environment allows the same vision. |
I'm with @eps1lon on this 👍 |
@gbirke vue-test-utils has un-deprecated isVisible(), so you can now use test-utils's isVisible() instead of jest-dom's toBeVisible(). See vuejs/vue-test-utils#1675 |
If you are using Vue, we recommend our Vue Testing Library package. It seems to me like there isn't a consensus on implementing this and the underlying issues are in |
Lock jest-dom library to version 5.11.9 until testing-library/jest-dom#338 is resolved
Due to the changes in the jest-dom library ( see testing-library/jest-dom#338 ), the vue-testing library un-deprecated the `isVisible` method. This change will allow us to update jest-dom.
Lock jest-dom library to version 5.11.9 until testing-library/jest-dom#338 is resolved
Describe the feature you'd like:
I think that it would make sense for
toBeVisible
to perform, in addition to its CSS-based checks, checks that confirm that the element is in the document.If we think about it from a CSS standpoint, yes, there is no CSS that is preventing the element from being visible. But from the user's perspective, the element is definitely not visible. For this reason I think it makes sense to change the behavior of
.toBeVisible
to include the checks from.toBeInTheDocument
.The text was updated successfully, but these errors were encountered: