我有一个简单的React组件如下:
class AutoComplete extends Component {
constructor() {
super();
this.state = {userName: ""};
}
_onChange(event) {
this.setState({userName: event.target.value});
}
render() {
return (
<div className="autoCompleteContainer" >
<input id="searchUsers" ref="searchUsers" onChange={this._onChange.bind(this)}
placeholder="Enter string" value={this.state.userName} />
<div className="searchIcon fa fa-search" ></div>
</div>
);
}
}
我为此写了一个酶测试:
describe("Testing chart", () => {
let spyOnChange = sinon.spy(Autocomplete.prototype, "_onChange");
let wrapper = mount(<Autocomplete/>);
it("should show correct list when typed something", () => {
wrapper.update();
wrapper.find("#searchUsers").simulate("change", {target: {value: "us"}});
//expect(spyOnChange.called).toEqual(true);
});
});
当我运行测试时,我收到错误:ReferenceError: event is not defined
。我在这做错了什么?我对另一个具有select标签的React组件进行了类似的测试,它在那里工作正常。这里看来有什么不对?
我正在使用Mocha作为测试运行员。
谢谢!