首先你輸入type =「number」,你輸入文字,其次你不處理onChange事件,這是你的輸入值應該更新的地方。看看下面的代碼
import React, { Component } from 'react';
class Test extends Component {
constructor(props) {
super(props);
this.state = {
value: ''
};
}
handleInputChange(e) {
this.setState({value: e.target.value});
}
render() {
return (
<input type="text" value={this.state.value} onChange={this.handleInputChange.bind(this)} />
);
}
}
export default Test;
,然後在測試做這樣的
describe("Test",() => {
const wrapper = mount(
<Test />
);
it("should enter valid value",() => {
wrapper.find('input').simulate('change', {target: {value: "hello!"}});
expect(wrapper.find('input').props().value).to.equal('hello!');
console.log(wrapper.find('input').props().value);
});
});
其實我原來的代碼有一個變化的函數和數值。我是在我的頭頂上寫了一個例子。感謝您的更正。 – ethankong113