-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Problem description:
- Having multiple versions of
@testing-library/dom
in the same project leads to bugs that are hard to catch, like confusing act warnings - To avoid this, we have to make sure that only one version of
@testing-library/dom
is installed - This is made hard by these facts:
@testing-library/dom
is a dependency to@testing-library/react
@testing-library/user-event
has a peer dependency to@testing-library/dom
- When using yarn pnp in strict mode, a package can only access a peer dependency if the direct parent has the package as a dependency (which makes sense)
So if I use both @testing-library/react
and @testing-library/user-event
(a common use case), my dependency tree needs to look like this right now:
my-project@npm:1.0.0
│ ├─ @testing-library/dom@npm:8.16.0 <--- possible conflict!
│ ├─ @testing-library/user-event@npm:14.2.5
│ ├─ @testing-library/react@npm:13.3.0
│ │ └─ @testing-library/dom@npm:8.16.0 <--- possible conflict!
And now it's easy for the two versions of @testing-library/dom
to diverge, leading to bugs. I have to use solutions like yarn's resolutions
field to keep them in sync.
Suggested solution:
Make all packages use the same instance of @testing-library/dom
by making it a peer dependency of @testing-library/react
.
I understand that this has the downside that the user has to install @testing-library/dom
alongside the react package, even if he doesn't need it. But as long as multiple testing-library packages need the same version of @testing-library/dom
, this seems to be the cleanest solution to ensure that everything works correctly.
If it was a peer dependency, the above dependency tree would look like this:
my-project@npm:1.0.0
│ ├─ @testing-library/dom@npm:8.16.0
│ ├─ @testing-library/user-event@npm:14.2.5
│ ├─ @testing-library/react@npm:13.3.0
Only one instance, problem solved!