Skip to content

Commit

Permalink
Merge pull request #1366 from spicyj/enterleave-testutils
Browse files Browse the repository at this point in the history
Make Simulate.mouseEnter/Leave use direct dispatch
  • Loading branch information
sophiebits committed Apr 13, 2015
2 parents 6d868a2 + 6b03975 commit d8117d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/browser/__tests__/ReactBrowserEventEmitter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var LISTENER = mocks.getMockFunction();
var ON_CLICK_KEY = keyOf({onClick: null});
var ON_TOUCH_TAP_KEY = keyOf({onTouchTap: null});
var ON_CHANGE_KEY = keyOf({onChange: null});
var ON_MOUSE_ENTER_KEY = keyOf({onMouseEnter: null});


/**
Expand Down Expand Up @@ -320,6 +321,17 @@ describe('ReactBrowserEventEmitter', function() {
expect(handleParentClick.mock.calls.length).toBe(0);
});

it('should have mouse enter simulated by test utils', function() {
ReactBrowserEventEmitter.putListener(
getID(CHILD),
ON_MOUSE_ENTER_KEY,
recordID.bind(null, getID(CHILD))
);
ReactTestUtils.Simulate.mouseEnter(CHILD);
expect(idCallOrder.length).toBe(1);
expect(idCallOrder[0]).toBe(getID(CHILD));
});

it('should infer onTouchTap from a touchStart/End', function() {
ReactBrowserEventEmitter.putListener(
getID(CHILD),
Expand Down
12 changes: 10 additions & 2 deletions src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,25 @@ function makeSimulator(eventType) {
node = domComponentOrNode;
}

var dispatchConfig =
ReactBrowserEventEmitter.eventNameDispatchConfigs[eventType];

var fakeNativeEvent = new Event();
fakeNativeEvent.target = node;
// We don't use SyntheticEvent.getPooled in order to not have to worry about
// properly destroying any properties assigned from `eventData` upon release
var event = new SyntheticEvent(
ReactBrowserEventEmitter.eventNameDispatchConfigs[eventType],
dispatchConfig,
ReactMount.getID(node),
fakeNativeEvent
);
assign(event, eventData);
EventPropagators.accumulateTwoPhaseDispatches(event);

if (dispatchConfig.phasedRegistrationNames) {
EventPropagators.accumulateTwoPhaseDispatches(event);
} else {
EventPropagators.accumulateDirectDispatches(event);
}

ReactUpdates.batchedUpdates(function() {
EventPluginHub.enqueueEvents(event);
Expand Down

0 comments on commit d8117d0

Please sign in to comment.