-
Notifications
You must be signed in to change notification settings - Fork 222
Fix nested wrappers bug in react-testing
#697
Conversation
a49fc3f
to
05e95e6
Compare
05e95e6
to
1b476c1
Compare
@@ -107,6 +107,8 @@ export class Root<Props> { | |||
}); | |||
|
|||
if (isPromise(result)) { | |||
updateWrapper(); |
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.
Hmm, I'm not sure I understand why you would do it here, also. if the result is a promise, there shouldn't be a reason to update until after the act block has finished, is there?
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.
If the function you triggered looks something like
async function doASubmit() {
setSomeLoadingState(true);
await sendSomeRequest();
setSomeLoadingState(false);
}
Then after synchronous execution pauses on the await there has been a state update, if we don't call updateWrapper
then any test for loading states in cases will fail.
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.
For this to make sense, setSomeLoadingState
has to run synchronously. I don't think that's guaranteed for async functions?
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.
Resolved in Slack, we agreed that this is probably the expected behaviour, and if they need to wait until any other update is finished and then update the tree, they can do so with act
@lemonmade @TheMallen updated the PR to do 2 things: Update: I removed those and still going with what I had initially. |
c230c46
to
1b476c1
Compare
@@ -107,6 +107,8 @@ export class Root<Props> { | |||
}); | |||
|
|||
if (isPromise(result)) { | |||
updateWrapper(); |
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.
Resolved in Slack, we agreed that this is probably the expected behaviour, and if they need to wait until any other update is finished and then update the tree, they can do so with act
This PR fixes a bug in react-testing where an unresolved promise required an additional
act()
around the state change.