diff --git a/src/renderers/dom/client/syntheticEvents/SyntheticEvent.js b/src/renderers/dom/client/syntheticEvents/SyntheticEvent.js
index 43eba76335..4a6c0a8412 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,
@@ -56,10 +57,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) {
@@ -70,7 +68,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 eef20cc22f..0e08a97b39 100644
--- a/src/test/__tests__/ReactTestUtils-test.js
+++ b/src/test/__tests__/ReactTestUtils-test.js
@@ -404,15 +404,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() {
@@ -426,15 +431,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() {