Skip to content

Make Simulate.mouseEnter/Leave use direct dispatch #1366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -398,17 +398,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