Skip to content

test: add missing test for suggestions #1215

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

Merged

Conversation

MatanBobi
Copy link
Member

What: Add a test that was missing for throwing suggestions

Why: While working on the docs requested in the discussion between @eps1lon and @timdeschryver, I saw that based on the implementation, there's a missing test.

Checklist:

  • Documentation added to the
    docs site - N/A
  • Tests
  • TypeScript definitions updated - N/A
  • Ready to be merged

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 17, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 183d075:

Sandbox Source
react-testing-library-examples Configuration

<button data-testid="foot">another</button>`)

expect(() => screen.getByTestId('foo', {suggest: true})).toThrowError()
configure({throwSuggestions: true})
Copy link
Member

Choose a reason for hiding this comment

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

These setup+cleanup tasks need to be in a beforeEach/afterEach. Otherwise the whole test run would be tainted if this single test fails.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since this is the only test needing them, I didn't want to add the overhead of running that code in a 'beforeEach' and 'afterEach' so I changed it at the beginning and returned it to what the 'beforeAll' hook defined. Do you think it will be better in this case to do it in the hooks instead?

Copy link
Member

Choose a reason for hiding this comment

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

every setup/cleanup for tests needs to be in hooks for the the reason I explained: once a test fails, the whole test run is tainted because because its cleanup didn't run. This can be super confusing if you try to debug the last test that fails when the only reason for that test failure is the first test.
Concretely:
say we have test 1 and 2. 1 needs environment A and 2 needs B. 1 sets up env A but fails. Now 2 also fails because it has env A+B. If you don't check the implementation of test 1 first, you might start debugging test 2 even though there's nothing in test 2 that needs fixing.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, that's a good point, thanks.
I've put the cleanup as part of the afterEach that was already there but I believe that the setup should remain within the test as it's the only test that needs this setup. Wdyt?

@codecov
Copy link

codecov bot commented Feb 17, 2023

Codecov Report

Merging #1215 (183d075) into main (4da0f39) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##              main     #1215   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines          992       992           
  Branches       322       322           
=========================================
  Hits           992       992           
Flag Coverage Δ
node-14 100.00% <ø> (ø)
node-16 100.00% <ø> (ø)
node-18 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@MatanBobi MatanBobi requested a review from eps1lon February 18, 2023 10:48
<button data-testid="foo">submit</button>
<button data-testid="foot">another</button>`)

expect(() => screen.getByTestId('foo', {suggest: true})).toThrowError()
Copy link
Member

Choose a reason for hiding this comment

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

This isn't really testing whether we're suggesting anything. Just that an error is thrown. I'll see if a snapshot makes more sense

@eps1lon eps1lon merged commit 3f64545 into testing-library:main Mar 8, 2023
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.

2 participants