Imagine a simple contentEditable
component with an oninput
event listener.
export default React.createClass({
render() {
return React.createElement('p', {
contentEditable: true,
onInput: this.emitChange
});
},
emitChange(e) {
console.log("Input event occurred", e);
}
});
In my test, I simulate an input
event on the component (like the user typing the letter a in the contentEditable
tag).
This works in the browser, I can click the component, press the a key and I will see an 'a' in the tag and the console.log
will trigger. I just can't get it to work in this test:
// Require the code from the block above.
var CE = require('content-editable');
describe('Component', function() {
it('updates state when we type', function() {
// Render a component instance and get a handle on it.
let ce = TestUtils.renderIntoDocument(<CE/>);
let _ce = ReactDOM.findDOMNode(ce);
TestUtils.Simulate.input(_ce, {
key: 'a'
});
expect(_ce.textContent).to.equal('a');
});
});
This test fails because _ce.textContent
is an empty string. I've tried simulating a click on the _ce
before simulating the input and it doesn't fix the problem.
How can I get my test to pass?