Skip to content

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

Merged
ljharb merged 3 commits into
enzymejs:masterfrom
chenesan:react-test-util-act
Mar 10, 2019
Merged

Wrap mount renderer render with reactTestUtils.act()#2034
ljharb merged 3 commits into
enzymejs:masterfrom
chenesan:react-test-util-act

Conversation

@chenesan

@chenesan chenesan commented Mar 6, 2019

Copy link
Copy Markdown
Contributor

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 .

Comment thread packages/enzyme-test-suite/test/ReactWrapper-spec.jsx Outdated

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown

@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
Copy Markdown

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

@ljharb

ljharb commented Mar 26, 2019

Copy link
Copy Markdown
Member

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

@pgangwani

Copy link
Copy Markdown

@ljharb Got it. Main intension was to know if there is impact after react/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