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

refactor(accordion): convert test to react-testing-library #6967

Merged
merged 2 commits into from
Sep 24, 2024

Conversation

robinzigmond
Copy link
Contributor

Proposed behaviour

Accordion component unit tests should use React Testing Library

Current behaviour

Tests use Enzyme

Checklist

  • Commits follow our style guide
  • Related issues linked in commit messages if required
  • Screenshots are included in the PR if useful
  • All themes are supported if required
  • Unit tests added or updated if required
  • Playwright automation tests added or updated if required
  • Storybook added or updated if required
  • Translations added or updated (including creating or amending translation keys table in storybook) if required
  • Typescript d.ts file added or updated if required
  • Related docs have been updated if required

QA

  • Tested in provided StackBlitz sandbox/Storybook
  • Add new Playwright test coverage if required
  • Carbon implementation matches Design System/designs
  • UI Tests GitHub check reviewed if required

Additional context

Testing instructions

expect(loggerSpy).toHaveBeenCalledWith(
"The `scheme` prop for `Accordion` component is deprecated and will soon be removed."
);
expect(loggerSpy).toHaveBeenCalledTimes(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

question(non-blocking): If we have only one Accordion component won't the loggerSpy only be called once anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤷 I put this in because the description includes the word "once". I'll want to remove that word if I remove that assertion - I don't think it makes much of a difference so happy to do it either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine. I have had a look elsewhere and we've done this same exact assertion with the same kind of wording. Keep it as is which means it'll be consistent.

expect(screen.getByText("child content")).toBeVisible();
});

it("mounts collapsed when `expanded prop` is passed as false", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick:

Suggested change
it("mounts collapsed when `expanded prop` is passed as false", () => {
it("mounts collapsed when `expanded` prop is passed as false", () => {

expect(screen.getByText("a subtitle")).toBeVisible();
});

it("does not adds a subtitle when `subTitle` prop is set and `size` is small", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick:

Suggested change
it("does not adds a subtitle when `subTitle` prop is set and `size` is small", () => {
it("does not add a subtitle when `subTitle` prop is set and `size` is small", () => {

Comment on lines 17 to 18
const loggerSpy = jest.spyOn(Logger, "deprecate").mockImplementation(() => {});
const consoleSpy = jest.spyOn(console, "error").mockImplementation(() => {});
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (non-blocking): We could set up and tear these down in the relevant tests instead to ensure we are only silencing the console when necessary, prevents other console warnings from being masked.

@DipperTheDan DipperTheDan marked this pull request as ready for review September 24, 2024 07:16
@DipperTheDan DipperTheDan requested a review from a team as a code owner September 24, 2024 07:17
@robinzigmond robinzigmond merged commit 332208f into master Sep 24, 2024
24 checks passed
@robinzigmond robinzigmond deleted the FE-5027-accordion-rtl branch September 24, 2024 09:02
@carbonci
Copy link
Collaborator

🎉 This PR is included in version 142.11.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants