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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about assertion name collisions between 2 libs extending jest #9678

Closed
DanielaValero opened this issue Mar 17, 2020 · 5 comments
Closed

Comments

@DanielaValero
Copy link

馃殌 Feature Proposal

Warn users when they have two matchers with colliding names. (and one is being overwritten silently)

Motivation

At the moment there is the case with jest-extended and testing-lib/dom.
Both libraries have an assertion called toBeEmpty.

In jest-extended, it checks for emptiness in data, in testing-lib/dom, it checks for emptiness in the DOM.

https://github.com/testing-library/jest-dom#tobeempty
https://github.com/jest-community/jest-extended#tobeempty

The situation is that as developers add both libraries in the project, one of the toBeEmpty will be silently overwritten, and when they start using them in their unit tests, and the test does not pass, regardless of being empty, they will not know what the problem is.

As there is no mechanism to decide which assertion names are already taken by libraries extending jest, an option to handle this, would be to warn users, as they install or run their tests, with 2 assertion names colliding, that the collision is happening, so that they can rename one of both in their projects

In my case I did by doing this as a very quick and dirty fix:

import {
  toBeEmpty as toBeEmptyNode,
} from '@testing-library/jest-dom/matchers';

expect.extend({ jestDomToBeEmpty });

Idea

I dont know the codebase in Jest to give more specific ideas, what I am thinking is, as they run their tests, to show a warning telling them that these 2 libs are using the same name for a matcher, and give them a link to find a solution to rename one in their configs.

For reference

I reported this in the author's libs, before deciding how to address this, would be helpful to read your thoughts on it.

testing-library/jest-dom#216

@gnapse
Copy link

gnapse commented Mar 17, 2020

Related to (or duplicate of) #6243

@darekkay
Copy link

Yes, both issues are highly related, but one may handle them separately. While #6243 addresses possible solutions, this issue talks about adding a warning (which might still be a good idea even after #6243 is implemented).

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

github-actions bot commented May 1, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants