反应:<输入>单元测试中从未更新的值 [英] React: <input> value never updated in unit test
问题描述
假设我有一个呈现 的组件.如果我尝试使用
ReactTestUtils.Simulate.change
对其进行单元测试,则组件会获取更新的值,但 DOM 中的 value
属性不会获取更新.
Say I have a component that renders an <input type="text" value="whatever">
. If I try to unit test it using ReactTestUtils.Simulate.change
, the component gets the updated value but then the value
attribute in the DOM doesn't get the update.
见https://jsfiddle.net/c1ht6zwm/3/
这当然是一个错误.肯定是.提高 https://github.com/facebook/react/issues/5934.>
Surely this is a bug. It must be. Raising https://github.com/facebook/react/issues/5934.
推荐答案
我认为 outerHTML
是标签及其(非事件)属性的动态反映.事实证明,它自己的值可能与其他属性不同步.正如 Davin 上面提到的,将 .outerHTML
更改为 .value
有效.
I thought outerHTML
was a dynamic reflection of the tag and its (non-event) properties. It turns out it's its own value that can be out of sync with other properties. As Davin mentioned above, changing .outerHTML
to .value
works.
这篇关于反应:<输入>单元测试中从未更新的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!