When shallow is used with lifecycleExperimental option as false, componentDidMount is called.
From shallow docs:
options.lifecycleExperimental: (Boolean [optional]): If set to true, the entire lifecycle (componentDidMount and componentDidUpdate) of the React component is called. The current default value is false with enzyme v2, but the next major version will flip the default value to true.
You can check the issue in this repo with example
Let me know if additional details are needed.
Thanks.
What version are you using? I think we would want to remove that flag more than fix any old compatibility.
Hi @blainekasten, is detailed in the repo's README:
"enzyme": "^3.1.0",
"enzyme-adapter-react-16": "^1.0.2",
I would expect that shallow's default behavior avoids running those methods that belongs to a mounted component, but per docs, that would be already changed:
but the next major version will flip the default value to true
lifecycleExperimental is gone; the flag you want to set is disableLifecycleMethods: true.
We may need to update the docs.
That option is the one I found to fix the unit tests after upgrading. Everything is in the repo I added at the beginning.
Agree, you may need to update the docs. Thanks.
@ljharb I can help with this.
Most helpful comment
@ljharb I can help with this.