Skip to content

Commit

Permalink
Make sure simulated events don't warn when providing extra event prop…
Browse files Browse the repository at this point in the history
…erties
  • Loading branch information
zpao committed Mar 30, 2016
1 parent 05b05c4 commit c9bd9e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions src/test/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <div onClick={handleClick} />;
}
});

var element = document.createElement('div');
var instance = ReactDOM.render(<Component />, 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 = () => <div><hr /></div>;
var SomeComponent = React.createClass({
Expand Down

0 comments on commit c9bd9e2

Please sign in to comment.