-
Notifications
You must be signed in to change notification settings - Fork 1
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
Support React 18 #613
Support React 18 #613
Conversation
await act(async () => { | ||
await expect(upload(fileData, file)).rejects.toThrow() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React 18 enforces act
more strictly. I couldn't figure out a way to get rid of the act
warning without using it directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inner function doesn't have to be async. This works for me:
await act(() => expect(upload(fileData, file)).rejects.toThrow())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly just a syntax thing. You can either return the promise directly or await it in the body. I took your suggestion
await act(async () => { | ||
await user.click(screen.getByText('Upload')) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why waiting for upload-success
works without showing an act console error, but simply waiting for upload-failure
does not work.
Let me know if you have any insights here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably doesn't help much, but I don't see any console errors removing the act
wrapper here. Test passes without warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly act
warnings are my kryptonite. I can't believe this works now 😭. Thank you 🙏
@josiasds I got started on this. There's still one test that is logging an |
Open issue related to this: testing-library/react-testing-library#1231 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
|
||
expect(input).toHaveValue('02/02/2023') | ||
await user.click(input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need user.click
here, as user.type
already focuses on the element. The test passes without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it open the popover menu though? I thought in doing testing earlier that it didn't open, but honestly I was trying a whole lot of things so maybe I was mistaken. I remember that my intent was to try and mimic the user's experience as much as possible
await act(async () => { | ||
await user.click(screen.getByText('Upload')) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably doesn't help much, but I don't see any console errors removing the act
wrapper here. Test passes without warnings.
await act(async () => { | ||
await expect(upload(fileData, file)).rejects.toThrow() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inner function doesn't have to be async. This works for me:
await act(() => expect(upload(fileData, file)).rejects.toThrow())
Resolves #568
Author Checklist