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

JSDOM-react adapter should implement isDisplayed #52

Open
NitayRabi opened this issue Mar 6, 2019 · 14 comments
Open

JSDOM-react adapter should implement isDisplayed #52

NitayRabi opened this issue Mar 6, 2019 · 14 comments
Labels
help wanted Extra attention is needed OSSGoodnessSquad

Comments

@NitayRabi
Copy link

NitayRabi commented Mar 6, 2019

Currently isDisplayed implementation under JSDOM adapter returns true.

Source
Method should test element visibility similar to -

Protractor

(e.g Test existence, size over 0 X 0 and display !== 'none')

@GabiGrin
Copy link
Contributor

I agree it shouldn't return true
the problem with jsdom is that you don't have proper measuring so you can't know

thus, I prefer to either:

  1. throw an error
  2. always return false

Thoughts? any other options we can do in JSDom?
@borisd9 @hepiyellow

@hepiyellow
Copy link
Contributor

hepiyellow commented Mar 10, 2019 via email

@GabiGrin
Copy link
Contributor

@hepiyellow what does it mean a "react" adapter alone? what environment does it run on?

@dor-itzhaki
Copy link

what about implementing this https://github.com/testing-library/jest-dom#tobevisible ?

@dor-itzhaki
Copy link

or just something like:

function isVisible (ele) {
    var style = window.getComputedStyle(ele);
    return  style.width !== "0" &&
    style.height !== "0" &&
    style.opacity !== "0" &&
    style.display!=='none' &&
    style.visibility!== 'hidden';
}

@GabiGrin
Copy link
Contributor

@dor-itzhaki height and width might be 0 on valid cases too, but I am OK with implementing the same logic the did on testing-library

@liorcode
Copy link
Contributor

liorcode commented Sep 3, 2020

Any progress on that? It took me a while to realize how come my tests always fail :( just when I used the debugger, I found this weird behaviour.
I think throwing an exception is much better than this unexpected behaviour, or going with the testing-library logic

@GabiGrin GabiGrin added the help wanted Extra attention is needed label Sep 6, 2020
@GabiGrin
Copy link
Contributor

GabiGrin commented Sep 6, 2020

@liorcode no, a PR should be fairly easy, the challenge will be coordinating this release with all users of WSR and ensuring nothing breaks unexpectedly

@liorcode
Copy link
Contributor

liorcode commented Sep 6, 2020

hmm I see. did you consider using some flag+warning for the new behavior and then removing it in the next major version of WSR? this is what WSR usually do for breaking changes.
e.g.

isDisplayed(realCheck = false) {
  if (!realCheck) { 
    console.warn('Warning: using mocked implementation of 'isDisplayed' which always returns true. This will change in the next version. Pass "true" to really check')
  }
}

@GabiGrin
Copy link
Contributor

GabiGrin commented Sep 7, 2020

@liorcode the warning is great meanwhile, can be added now.
As for the fix, I prefer following semver and release a new major of the react jsdom adapter and have WSR upgrade at will

@shlomitc thoughts?

@shlomitc
Copy link

shlomitc commented Sep 7, 2020

I went through our code and didn't see anywhere we're using the isDisplayed() method in our code, so probably this will not break us.
@liorcode - where did this happen to you?
Overall I'm ok with both warning and error, as long as it is clear and displayed well in the logs.

@liorcode
Copy link
Contributor

liorcode commented Sep 7, 2020

It happened for me when I used my own drivers, not WSR. I did some tests to make sure some element was not displayed, and I was very surprised when it failed. took me a while to realize that isDisplayed returned true for no reason :)

@AlmogAdziashvili
Copy link

@GabiGrin
According to jest-dom doc:

An element is visible if all the following conditions are met:

- it does not have its css property display set to none
- it does not have its css property visibility set to either hidden or collapse
- it does not have its css property opacity set to 0
- its parent element is also visible (and so on up to the top of the DOM tree)

what do you think?

@GabiGrin
Copy link
Contributor

@AlmogAdziashvili Sounds good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed OSSGoodnessSquad
Projects
None yet
Development

No branches or pull requests

7 participants