@samitouri / QOS-React-2 / commits / 94d536f2ef

add tests for React.addons.TestUtils.Simulate.change

Domenico Matteo committed Jul 24, 2015 at 22:26 UTC 94d536f2efadfa3dacaa93f40ea9caaa5555e35e
1 file changed +35
src/test/__tests__/ReactTestUtils-test.js
+35
@@ -309,4 +309,39 @@ describe('ReactTestUtils', function() {
309 expect(ReactTestUtils.isDOMComponent(component.refs.head)).toBe(true);
310 expect(ReactTestUtils.isDOMComponent(component.refs.body)).toBe(true);
311 });
312 +
313 + it('should change the value of an input field', function() {
314 + var handler = jasmine.createSpy('spy');
315 + var container = document.createElement('div');
316 + var instance = React.render(<input type="text" onChange={handler} />, container);
317 +
318 + var node = React.findDOMNode(instance);
319 + node.value = 'giraffe';
320 + ReactTestUtils.Simulate.change(node);
321 +
322 + expect(handler).toHaveBeenCalledWith(jasmine.objectContaining({target: node}));
323 + });
324 +
325 + it('should change the value of an input field in a component', function() {
326 + var SomeComponent = React.createClass({
327 + render: function() {
328 + return (
329 + <div>
330 + <input type="text" ref="input" onChange={this.props.handleChange} />
331 + </div>
332 + );
333 + },
334 + });
335 +
336 + var handler = jasmine.createSpy('spy');
337 + var container = document.createElement('div');
338 + var instance = React.render(<SomeComponent handleChange={handler} />, container);
339 +
340 + var node = React.findDOMNode(instance.refs.input);
341 + node.value = 'zebra';
342 + ReactTestUtils.Simulate.change(node);
343 +
344 + expect(handler).toHaveBeenCalledWith(jasmine.objectContaining({target: node}));
345 + });
346 +
347 });