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

Wrap mount renderer render with reactTestUtils.act() #2034

Merged
merged 3 commits into from
Mar 10, 2019

Conversation

chenesan
Copy link
Contributor

@chenesan chenesan commented Mar 6, 2019

This PR wrap the render function of mount renderer with act() so that use cases with useEffect would work. The test is the test case in https://github.com/threepointone/react-act-examples/blob/master/README.md#effects .

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Thanks, this is great!

@ljharb ljharb force-pushed the react-test-util-act branch 2 times, most recently from 4926f6e to 35ec8fb Compare March 10, 2019 07:05
@ljharb ljharb merged commit 35ec8fb into enzymejs:master Mar 10, 2019
@pgangwani
Copy link

@chenesan : Glad to see this PR merged.

ljharb added a commit that referenced this pull request Mar 13, 2019
 - [new] Wrap renders in `TestUtils.act` (#2034)
 - [fix] `shallow`: Mock sCU if gDSFP defined in shallow renderer rerender (#1981)
 - [fix] add `hasShouldComponentUpdateBug` to gDSFP lifecycles option (#1981)
 - [deps] update `react-is`, `enzyme-adapter-utils`, `prop-types`
ljharb added a commit that referenced this pull request Mar 14, 2019
@pgangwani
Copy link

@chenesan @ljharb Can we implement same changes for ShallowRenderer too considering facebook/react#15120 ? Please correct me if my understanding is wrong.

@ljharb
Copy link
Member

ljharb commented Mar 26, 2019

@pgangwani I had to revert the act-wrapping in shallow because it requires a DOM, which shallow must not.

@pgangwani
Copy link

@ljharb Got it. Main intension was to know if there is impact after facebook/react#15120 is merged.

robertknight added a commit to preactjs/enzyme-adapter-preact-pure that referenced this pull request Apr 14, 2019
Flush any effects scheduled with `useEffect` using the `act` helper
on the initial render.

This means that in a test a developer can write:

```
const wrapper = mount(<ComponentThatUsesEffects/>)
```

And know that effects will have been run before they start interacting
with the result wrapper.

See enzymejs/enzyme#2034 for corresponding change
to the React adapter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants