From 69c91b71b129aaf1c75bf6f04bc797af2bc66f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Wed, 30 Mar 2016 11:57:27 -0700 Subject: [PATCH] Make sure simulated events don't warn when providing extra event properties --- src/test/ReactTestUtils.js | 3 +++ src/test/__tests__/ReactTestUtils-test.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/test/ReactTestUtils.js b/src/test/ReactTestUtils.js index 4f8e4ebb38c2b..62a7f4f426665 100644 --- a/src/test/ReactTestUtils.js +++ b/src/test/ReactTestUtils.js @@ -499,6 +499,9 @@ function makeSimulator(eventType) { fakeNativeEvent, node ); + // Since we aren't using pooling, always persist the event. This will make + // sure it's marked and won't warn when setting additional properties. + event.persist(); assign(event, eventData); if (dispatchConfig.phasedRegistrationNames) { diff --git a/src/test/__tests__/ReactTestUtils-test.js b/src/test/__tests__/ReactTestUtils-test.js index a7cf4ab846536..81fda9cebf652 100644 --- a/src/test/__tests__/ReactTestUtils-test.js +++ b/src/test/__tests__/ReactTestUtils-test.js @@ -474,6 +474,29 @@ describe('ReactTestUtils', function() { expect(handler).not.toHaveBeenCalled(); }); + it('should not warn when simulating events with extra properties', function() { + spyOn(console, 'error'); + + var CLIENT_X = 100; + + var Component = React.createClass({ + handleClick: function(e) { + expect(e.clientX).toBe(CLIENT_X); + }, + render: function() { + return
; + }, + }); + + var element = document.createElement('div'); + var instance = ReactDOM.render(, element); + ReactTestUtils.Simulate.click( + ReactDOM.findDOMNode(instance), + {clientX: CLIENT_X} + ); + expect(console.error.calls.length).toBe(0); + }); + it('can scry with stateless components involved', function() { var Stateless = () =>

; var SomeComponent = React.createClass({