-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(act): Support async act 🎉 #343
Conversation
Codecov Report
@@ Coverage Diff @@
## master #343 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 2 2
Lines 43 62 +19
Branches 7 10 +3
=====================================
+ Hits 43 62 +19
Continue to review full report at Codecov.
|
Note: That even having an outdated dom-testing-library works fine. I didn't think it would, but it makes sense now so that's cool :) |
c388663
to
b4d3076
Compare
src/act-compat.js
Outdated
) | ||
} | ||
// make all effects resolve before | ||
act(() => {}) |
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.
we went back and forth on this, and decided not to flush in the beginning. is there a reason you added this 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.
Thanks for that! I wasn't sure whether this was correct 😅 I'll remove that.
b4d3076
to
e1c2c0c
Compare
`) | ||
expect(callback).toHaveBeenCalledTimes(1) | ||
|
||
// and it doesn't warn you twice |
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.
e1c2c0c
to
df1a41c
Compare
This looks good to go from my perspective. I'll leave it open for a while for folks to review if they want. |
Saweeet! Off it goes. |
@@ -19,8 +34,28 @@ function actPolyfill(cb) { | |||
|
|||
const act = reactAct || actPolyfill | |||
|
|||
function rtlAct(...args) { | |||
return act(...args) | |||
let youHaveBeenWarned = false |
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.
😂
🎉 This PR is included in version 6.1.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Do we have to |
you'll have to wrap await act(async () => {
fireEvent(...)
}) you could write a helper of course async function fireEventAsync(){
await act(async () => {
fireEvent(...)
})
}
// ...
await fireEventAsync() |
@threepointone it was already wrapped in the previous version https://github.com/kentcdodds/react-testing-library/blob/master/src/index.js#L100 Wondering if this changes the required usage to need await |
We don't need a
Bottom line: We're solid. |
Oh haha I forgot facepalm your lib is awesome |
@kentcdodds Can you please elaborate on how is |
fireEvent.click(loadGreeting)
const greetingNode = await findByText(/hello/i) |
Oh wow, this is going to take some time to process. So far I've been using So to be clear, if I am doing something else besides finding elements, eg. |
No. You should never have to wrap a |
Also, |
Well, so I made some convoluted example, but I am doing similar stuff fairly often. Sadly it's not passing and do wonder what's is the proper way out of it. const TestComponent = () => {
const [state, setState] = React.useState(1)
const onClick = () => {
setImmediate(() => {
setState(i => i + 1)
})
}
return (
<>
<button onClick={onClick}>GO</button>
<div>{state}</div>
</>
)
}
test('nay', () => {
const { getByText, container } = render(<TestComponent />)
fireEvent.click(getByText('GO'))
expect(container.textContent).toBe('GO2')
}) There is also an attempt to solve it with Sorry, I should have probably made a new issue, but I am kinda tired here and heading to bed. That might be also a reason why I missed something there 🤷♂️ |
That's pretty weird. |
Sorry, have no capacity for diving deep in there right now. I don't think I will ever need I've updated the CodeSandbox with two passing tests and one failing ( |
What: Add support for async
act
Why: Closes #281
How: Unfortunately, we need to do a bit of attempts at polyfilling to ensure we support [email protected] for the foreseeable future. This means that we not only have to polyfill
act
itself, but also polyfill the async support ofact
. So I've done my best to detect whetheract
supports async. I feel pretty good about this solution. I'd rather this than detecting the version number anyway.Checklist: