mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #1366 from spicyj/enterleave-testutils
Make Simulate.mouseEnter/Leave use direct dispatch
This commit is contained in:
@@ -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});
|
||||
|
||||
|
||||
/**
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user