【发布时间】:2016-02-29 10:09:57
【问题描述】:
我用 React 做了很多组件测试。最后,我在 DOM (renderIntoDocument) 和 Shallow 渲染之间切换,我有两个问题:
- 为什么在 Shallow 渲染中没有触发 componentDidMount?
- 是否可以通过DOM方式触发componentWillReceiveProps?
谢谢
【问题讨论】:
-
有一个线程 here 要求以某种方式在浅层渲染中触发 componentDidMount。为什么还没有呢?可能是 a) 仍在开发中的浅渲染和 b) 浅渲染不渲染子级的混合,并且 componentDidMount 通常仅在渲染所有子级后才渲染。在this answer on SO 中似乎有一个解释如何更新 DOM 方法/renderIntoDocument,以触发 componentWillReceiveProps。
-
谢谢@wintvelt。这对我来说是一个很好的答案,如果您将评论移到答案中,我会验证它。
标签: javascript unit-testing reactjs