diff --git a/src/renderers/dom/client/syntheticEvents/SyntheticEvent.js b/src/renderers/dom/client/syntheticEvents/SyntheticEvent.js index 2a827a356f..bf792788fc 100644 --- a/src/renderers/dom/client/syntheticEvents/SyntheticEvent.js +++ b/src/renderers/dom/client/syntheticEvents/SyntheticEvent.js @@ -23,6 +23,7 @@ var warning = require('warning'); */ var EventInterface = { type: null, + target: null, // currentTarget is set when dispatching; no use in copying it here currentTarget: emptyFunction.thatReturnsNull, eventPhase: null, @@ -55,10 +56,7 @@ var EventInterface = { function SyntheticEvent(dispatchConfig, targetInst, nativeEvent, nativeEventTarget) { this.dispatchConfig = dispatchConfig; this._targetInst = targetInst; - this.nativeEvent = nativeEvent; - this.target = nativeEventTarget; - this.currentTarget = nativeEventTarget; var Interface = this.constructor.Interface; for (var propName in Interface) { @@ -69,7 +67,11 @@ function SyntheticEvent(dispatchConfig, targetInst, nativeEvent, nativeEventTarg if (normalize) { this[propName] = normalize(nativeEvent); } else { - this[propName] = nativeEvent[propName]; + if (propName === 'target') { + this.target = nativeEventTarget; + } else { + this[propName] = nativeEvent[propName]; + } } } diff --git a/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js b/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js index b667799538..e7e3d29fe3 100644 --- a/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js +++ b/src/renderers/dom/client/syntheticEvents/__tests__/SyntheticEvent-test.js @@ -72,6 +72,15 @@ describe('SyntheticEvent', function() { expect(syntheticEvent.isPersistent()).toBe(true); }); + it('should be nullified if the synthetic event has called destructor', function() { + var target = document.createElement('div'); + var syntheticEvent = createEvent({srcElement: target}); + syntheticEvent.destructor(); + expect(syntheticEvent.type).toBe(null); + expect(syntheticEvent.nativeEvent).toBe(null); + expect(syntheticEvent.target).toBe(null); + }); + it('should warn if the synthetic event has been released when calling `preventDefault`', function() { spyOn(console, 'error'); var syntheticEvent = createEvent({}); diff --git a/src/test/__tests__/ReactTestUtils-test.js b/src/test/__tests__/ReactTestUtils-test.js index 2b044d7d2e..a0c2700a25 100644 --- a/src/test/__tests__/ReactTestUtils-test.js +++ b/src/test/__tests__/ReactTestUtils-test.js @@ -431,15 +431,20 @@ describe('ReactTestUtils', function() { }); it('should change the value of an input field', function() { - var handler = jasmine.createSpy('spy'); + var obj = { + handler: function(e) { + e.persist(); + }, + }; + spyOn(obj, 'handler').andCallThrough(); var container = document.createElement('div'); - var instance = ReactDOM.render(, container); + var instance = ReactDOM.render(, container); var node = ReactDOM.findDOMNode(instance); node.value = 'giraffe'; ReactTestUtils.Simulate.change(node); - expect(handler).toHaveBeenCalledWith(jasmine.objectContaining({target: node})); + expect(obj.handler).toHaveBeenCalledWith(jasmine.objectContaining({target: node})); }); it('should change the value of an input field in a component', function() { @@ -453,15 +458,20 @@ describe('ReactTestUtils', function() { }, }); - var handler = jasmine.createSpy('spy'); + var obj = { + handler: function(e) { + e.persist(); + }, + }; + spyOn(obj, 'handler').andCallThrough(); var container = document.createElement('div'); - var instance = ReactDOM.render(, container); + var instance = ReactDOM.render(, container); var node = ReactDOM.findDOMNode(instance.refs.input); node.value = 'zebra'; ReactTestUtils.Simulate.change(node); - expect(handler).toHaveBeenCalledWith(jasmine.objectContaining({target: node})); + expect(obj.handler).toHaveBeenCalledWith(jasmine.objectContaining({target: node})); }); it('should throw when attempting to use ReactTestUtils.Simulate with shallow rendering', function() {