@samitouri / QOS-React / commits / 42b1cba048

Make sure simulated events don't warn when providing extra event properties

Paul O’Shannessy committed Mar 30, 2016 at 11:57 UTC 42b1cba0486a846f355bdc8005de4b2bfdea9010
3 files changed +30 -1
src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js
+4 -1
@@ -144,7 +144,10 @@ describe('SyntheticEvent', function() {
144 );
145 });
146
147 - it('should properly log warnings when events simulated with rendered components', function() {
147 + // TODO: reenable this test. We are currently silencing these warnings when
148 + // using TestUtils.Simulate to avoid spurious warnings that result from the
149 + // way we simulate events.
150 + xit('should properly log warnings when events simulated with rendered components', function() {
151 spyOn(console, 'error');
152 var event;
153 var element = document.createElement('div');
src/test/ReactTestUtils.js
+3
@@ -498,6 +498,9 @@ function makeSimulator(eventType) {
498 fakeNativeEvent,
499 node
500 );
501 + // Since we aren't using pooling, always persist the event. This will make
502 + // sure it's marked and won't warn when setting additional properties.
503 + event.persist();
504 Object.assign(event, eventData);
505
506 if (dispatchConfig.phasedRegistrationNames) {
src/test/__tests__/ReactTestUtils-test.js
+23
@@ -474,6 +474,29 @@ describe('ReactTestUtils', function() {
474 expect(handler).not.toHaveBeenCalled();
475 });
476
477 + it('should not warn when simulating events with extra properties', function() {
478 + spyOn(console, 'error');
479 +
480 + var CLIENT_X = 100;
481 +
482 + var Component = React.createClass({
483 + handleClick: function(e) {
484 + expect(e.clientX).toBe(CLIENT_X);
485 + },
486 + render: function() {
487 + return <div onClick={this.handleClick} />;
488 + },
489 + });
490 +
491 + var element = document.createElement('div');
492 + var instance = ReactDOM.render(<Component />, element);
493 + ReactTestUtils.Simulate.click(
494 + ReactDOM.findDOMNode(instance),
495 + {clientX: CLIENT_X}
496 + );
497 + expect(console.error.calls.length).toBe(0);
498 + });
499 +
500 it('can scry with stateless components involved', function() {
501 var Stateless = () => <div><hr /></div>;
502 var SomeComponent = React.createClass({