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

add @testing-library/react #3302

Merged

Conversation

petermakowski
Copy link
Contributor

Done

  • add @testing-library/react
    • set custom testIdAttribute for getByTestId to work

QA

MAAS deployment

To run this branch you will need access to one of the following MAAS deployments:

Running the branch

You can run this branch by:

QA steps

  • Steps for QA.

Fixes

Fixes: # .

Launchpad issue

Related Launchpad maas issue in the form lp#number.

Backports

In general, please propose fixes against master rather than release branches (e.g. 2.7), unless the fix is only applicable for that specific release. Please apply backport labels to the PR (e.g. "Backport 2.7") for the appropriate releases to target.

Only bug and security fixes should be backported, new features should only land in master.

- set custom testIdAttribute for getByTestId to work
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
import Enzyme from "enzyme";
import { enableFetchMocks } from "jest-fetch-mock";

Enzyme.configure({ adapter: new Adapter() });

configure({ testIdAttribute: "data-test" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if this also maintains functionality for data-testid ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This will need to be removed once #3295 is merged to use the default test id ('data-testid').

Copy link
Contributor

@huwshimi huwshimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not fragment this codebase further until we have a good plan about migrating the entire codebase. This has been discussed a number of times already which you wouldn't be aware of @petermakowski, but we've agreed not to do this until someone comes up with a good plan for using RTL without the poor testing practices it encourages.

@petermakowski
Copy link
Contributor Author

Let's not fragment this codebase further until we have a good plan about migrating the entire codebase. This has been discussed a number of times already which you wouldn't be aware of @petermakowski, but we've agreed not to do this until someone comes up with a good plan for using RTL without the poor testing practices it encourages.

@huwshimi Couldn't agree more that we shouldn't start the migration without planning!

But this PR is only adding testing-library/react as a dependency with basic setup - I'm not introducing anything controversial here. AFAIK everybody's on board with the idea that we're gonna have to stop using enzyme and replace it with testing-library eventually. Unless you have concerns with the incremental approach itself?

Could you point me to where you had the discussion about RTL, I'd like to better understand your concerns around it.

@petermakowski
Copy link
Contributor Author

@huwshimi I'd personally find it very useful to have RTL as a dependency on master. Would allow to experiment easily with various ways of testing in the repo as I go - without having to constantly switch branches - this would help inform the planning and our approach.

Just to reiterate - no RTL test will be written before having a plan that everybody's had a chance to contribute to and approved.

@hatched
Copy link
Contributor

hatched commented Nov 22, 2021

@petermakowski and I have had a discussion about a plan to migrate the tests. But in any event this should land to allow him to carry on with the test investigations.

@hatched
Copy link
Contributor

hatched commented Nov 22, 2021

@petermakowski can you update this to master and ensure a passing CI run

@huwshimi
Copy link
Contributor

@petermakowski and I have had a discussion about a plan to migrate the tests. But in any event this should land to allow him to carry on with the test investigations.

I think if this is just going to be for investigation that it might make more sense for it to be done in a fork, rather than having to maintain extra deps in master.

@huwshimi
Copy link
Contributor

Let's not fragment this codebase further until we have a good plan about migrating the entire codebase. This has been discussed a number of times already which you wouldn't be aware of @petermakowski, but we've agreed not to do this until someone comes up with a good plan for using RTL without the poor testing practices it encourages.

@huwshimi Couldn't agree more that we shouldn't start the migration without planning!

But this PR is only adding testing-library/react as a dependency with basic setup - I'm not introducing anything controversial here. AFAIK everybody's on board with the idea that we're gonna have to stop using enzyme and replace it with testing-library eventually. Unless you have concerns with the incremental approach itself?

Could you point me to where you had the discussion about RTL, I'd like to better understand your concerns around it.

Thanks for understanding @petermakowski. We started a document to begin the discussion: https://docs.google.com/document/d/1ysVlPByzVY-NBUjGic1WupHojUl30P6cf3Xe-OVRRPg/edit#. We haven't really got a good plan figured out for how to do good unit testing with RTL rather than the integration/accessibility/bdd style that RTL promotes. We also need to figure out a good plan for how/when to do such a large migration. Probably after the existing migrations are completed (Angular JS being the main piece in progress).

@petermakowski petermakowski merged commit d25cf07 into canonical:master Nov 23, 2021
@petermakowski
Copy link
Contributor Author

petermakowski commented Nov 23, 2021

Thanks for explaining @huwshimi

As part of the investigation I created an epic to track this migration with a full list of files: #3318

Feel free to add more tasks.

Let's make sure we address all concerns in the document https://docs.google.com/document/d/1ysVlPByzVY-NBUjGic1WupHojUl30P6cf3Xe-OVRRPg

@petermakowski petermakowski deleted the add-testing-library-react branch May 9, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants