, TestUtils.Simulate DOM, React . , , , , , :
export default React.createClass({
propTypes: {
onChange: React.PropTypes.func
},
render() {
return React.createElement('p', {
contentEditable: true,
onInput: this.emitChange
});
},
emitChange(e) {
if (this.props.onChange) {
this.props.onChange(e);
}
}
});
, onChange :
describe('Component', function() {
it('updates state when we type', function() {
let changeFired = false;
let ce = TestUtils.renderIntoDocument(<CE onChange={verify} />);
let _ce = ReactDOM.findDOMNode(ce);
TestUtils.Simulate.input(_ce, {
key: 'a'
});
function verify(e) {
changeFired = true;
expect(e.key).to.equal('a');
}
expect(changeFired).to.equal(true);
});
});
unit test emitChange . , , unit test, , DOM, , , , , - , , - .
unit test DOM textContent innerHTML, . , () .