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

Make @testing-library/dom a peer dependency #70

Open
gndelia opened this issue Apr 6, 2021 · 3 comments · May be fixed by #126
Open

Make @testing-library/dom a peer dependency #70

gndelia opened this issue Apr 6, 2021 · 3 comments · May be fixed by #126

Comments

@gndelia
Copy link

gndelia commented Apr 6, 2021

Hi. First of all, thanks for this library, it works great for testing with react-select, which help us avoiding those ugly querySelector calls 😅

I'm using @testing-library/react which ships with its own version of @testing-library/dom, which may be different from the one used by this package. The issue we faced is that, suddenly, after installing this library, many tests started to fail, even though none of these were using this library. We think this discrepancy is due to the fact that this library adds another version of @testing-library/dom

If I understand correctly, as this works as a "plugin" of @testing-library/react it shouldn't be necessary to ship @testing-library/dom as a dependency, but as a peer dependency, as the consumers of this library will provide the proper version. Peer dependencies also allow to specify the minimum version required to work (in this case, >= 7).

Does that makes sense?

@pom421
Copy link

pom421 commented Jul 1, 2021

I got a problem similar to yours @gndelia.

I upgraded to

  • "jest": "^27.0.6",
  • "@testing-library/jest-dom": "^5.11.10",
  • "@testing-library/react": "^12.0.0",
  • "react-select-event": "^5.3.0",

I had to use explicitly the jsdom environement in my test files (@jest-environment jsdom).

Then the test using react-select-event throws an error :

  ● Test suite failed to run

    ReferenceError: clearImmediate is not defined

       6 | import * as nextRouter from "next/router"
       7 | import React from "react"
    >  8 | import selectEvent from "react-select-event"
         | ^
       9 |
      10 | import { WizardForm } from "@/components/wizard"
      11 | import * as mockScrollTop from "@/hooks/useScrollTop"

      at runWithJestRealTimers (node_modules/react-select-event/node_modules/@testing-library/dom/dist/helpers.js:31:5)

In yarn.lock, we see that react-select-event depends of @testing-library/dom v7.

react-select-event@^5.3.0:
  version "5.3.0"
  resolved "https://registry.yarnpkg.com/react-select-event/-/react-select-event-5.3.0.tgz#4548fffd615a47176951cbb301ee21a0c60b582a"
  integrity sha512-Novkl7X9JJKmDV5LyYaKwl0vffWtqPrBa1vuI0v43P/f87mSA7JfdYxU93SFb99RssphVzBSIAbcnbX1w21QIQ==
  dependencies:
    "@testing-library/dom" ">=7"

This configuration prevents to have the @testing-library/dom in v8, which removes the use of clearImmediate and setImmediate (reference : testing-library/dom-testing-library#914)

I don't know how peer dependency works, so I can't answer to the proposed solution by @gndelia.
At least, it would be necessary to depends of @testing-library/dom v8.

@romgain
Copy link
Owner

romgain commented Jul 9, 2021

Hi both!

Thank you for reporting this!

Would either of you be open to submitting a PR to fix this?

Thanks again!   😊

@gndelia
Copy link
Author

gndelia commented Jul 20, 2021

Hi! I've changed my work's project since opening this ticket, so I'm not currently using it 😅 (not event RTL), so I don't think I can properly test it. If I get the chance to work again with the libraries, and the issue is open, I'll do the PR

@jackw jackw linked a pull request Sep 16, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants