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

chore(tests): Fix uncalled .toBeInTheDocument and .toBeTruthy referen… #12892

Merged
merged 1 commit into from
May 20, 2022

Conversation

pdehaan
Copy link
Contributor

@pdehaan pdehaan commented May 16, 2022

…ces in tests

Because

  • .toBeInDocument should be .toBeInDocument(), etc.

This pull request

  • Fixes the errors, but doesn't add ESLint rules to catch future breakages, I'll file that as a separate issue.

Issue that this pull request solves

Closes: #12868

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Screenshots (Optional)

Please attach the screenshots of the changes made in case of change in user interface.

Other information (Optional)

Any other information that is important to this pull request.

Copy link
Contributor

@dschom dschom left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@LZoog LZoog left a comment

Choose a reason for hiding this comment

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

I know I mentioned this on Slack but just also calling out here that test_pull_request didn't run. I'm pretty certain this one doesn't pass locally since I tried fixing that one before.

We had some issues with CI running last week, I can't tell if that's what's happened here or if it didn't run since you're not in fxa-devs? 🤔 But either way, if you run yarn test in fxa-settings you should see at least that one fail (unless I'm somehow mistaken on that not passing). If that's something you can investigate I can come back and re-review/pull your commit into a different branch, or otherwise, we can have a separate ticket for just that one failure and I can r+ the rest.

@@ -23,7 +23,7 @@ describe('BentoMenu', () => {

fireEvent.click(toggleButton);
expect(toggleButton).toHaveAttribute('aria-expanded', 'true');
expect(dropDown).toBeInTheDocument;
expect(dropDown).toBeInTheDocument();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, not what I expected...
Getting 6 failures locally and they all seem to be related to things being null:

  ● BentoMenu › renders and toggles as expected with default values

    expect(received).toBeInTheDocument()

    received value must be an HTMLElement or an SVGElement.
    Received has value: null

      24 |     fireEvent.click(toggleButton);
      25 |     expect(toggleButton).toHaveAttribute('aria-expanded', 'true');
    > 26 |     expect(dropDown).toBeInTheDocument();
         |                      ^
      27 |
      28 |     fireEvent.click(toggleButton);
      29 |     expect(toggleButton).toHaveAttribute('aria-expanded', 'false');

      at __EXTERNAL_MATCHER_TRAP__ (../../node_modules/react-scripts/node_modules/expect/build/index.js:342:30)
      at Object.toBeInTheDocument (../../node_modules/react-scripts/node_modules/expect/build/index.js:343:15)
      at Object.<anonymous> (src/components/BentoMenu/index.test.tsx:26:22)

So it seems to pass if I change it to expect(dropDown).toBeNull(), but not sure if that's correct/expected here and 5 other places:

  • src/components/DropDownAvatarMenu/index.test.tsx:64
  • src/components/DropDownAvatarMenu/index.test.tsx:95
  • src/components/DropDownAvatarMenu/index.test.tsx:113
  • src/components/BentoMenu/index.test.tsx:26
  • src/components/BentoMenu/index.test.tsx:38
  • src/components/BentoMenu/index.test.tsx:54

received value must be an HTMLElement or an SVGElement.
Received has value: null

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, those should not be null. That's what I was running into as well.

If you revert the BentoMenu and DropDownAvatarMenu changes, I can pull your commit into another PR for you (we actually have docs on how to do this here FWIW), and then we can have a separate issue to fix those remaining ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/giphy "As you wish"

git grep -n ".toBe" packages | grep -Ev "\.toBe.*\("

packages/fxa-settings/src/components/BentoMenu/index.test.tsx:26:    expect(dropDown).toBeInTheDocument;
packages/fxa-settings/src/components/BentoMenu/index.test.tsx:38:    expect(dropDown).toBeInTheDocument;
packages/fxa-settings/src/components/BentoMenu/index.test.tsx:54:    expect(dropDown).toBeInTheDocument;

packages/fxa-settings/src/components/DropDownAvatarMenu/index.test.tsx:64:    expect(dropDown).toBeInTheDocument;
packages/fxa-settings/src/components/DropDownAvatarMenu/index.test.tsx:95:    expect(dropDown).toBeInTheDocument;
packages/fxa-settings/src/components/DropDownAvatarMenu/index.test.tsx:113:    expect(dropDown).toBeInTheDocument;

@LZoog
Copy link
Contributor

LZoog commented May 20, 2022

@pdehaan Running CI now. When you see it passes, do you mind fixing up your previous commit so there's only one that will be merged? When you force push CI won't run again but that's fine, will r+/merge and close #12965

@LZoog
Copy link
Contributor

LZoog commented May 20, 2022

@pdehaan I think you need to rebase against main for CI to get the sr-LATN fix. Do you mind rebasing & squashing your commits, and then I'll pull that commit into that other branch?

Sorry this is turning into so much trouble for what this fixes 🤣

…ces in tests

Revert the BentoMenu and DropDownAvatarMenu changes
Copy link
Contributor

@LZoog LZoog left a comment

Choose a reason for hiding this comment

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

@pdehaan Will you file that follow up to fix the tests that failed? Thank you! 🙏

@LZoog LZoog merged commit 8fada53 into main May 20, 2022
@pdehaan
Copy link
Contributor Author

pdehaan commented May 21, 2022

@pdehaan Will you file that follow up to fix the tests that failed? Thank you! 🙏

Filed as #12978

@pdehaan pdehaan deleted the pdehaan/12868 branch May 21, 2022 15:45
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 this pull request may close these issues.

Fix uncalled .toBeInTheDocument and .toBeTruthy references in tests
3 participants