我正在尝试测试以下代码。
componentDidMount() {
this.refdInput.addEventListener("fieldInput", this.onChange);
this.refdInput.addEventListener("fieldInput", this.onBlur);
this.refdInput.addEventListener("fieldInput", this.onFocus);
}
<input
id="float-input-component"
type="text"
className={classes.join(" ")}
ref={elem => {this.refdInput = elem;}}
/>
具体来说,我试过
var el = document.getElementById("float-input-component");
el.addEventListener('fieldInput', onChange());
el.addEventListener('fieldInput', onBlur());
el.addEventListener('fieldInput', onFocus());
我收到以下错误消息:TypeError:无法读取未定义的属性"addEventListener"。我做错了什么?
因为addEventListener是在componentDidMount中调用的。在Jest中,成分应该是装载的(酶(,而不是浅的或呈现的
const renderedInputComponent = mount(...)