@samitouri / QOS-React-2 / commits / 6b03975395

Make Simulate.mouseEnter/Leave use direct dispatch

Fixes #1297. onMouseEnter and onMouseLeave shouldn't *actually* use direct dispatch, but doing so is more useful than doing nothing (and I don't think it precludes adding proper enter/leave dispatching later, either). Test Plan: grunt test

Ben Alpert committed Feb 16, 2015 at 16:12 UTC 6b0397539595f0cd2a052ca80ef980d6c6580621
2 files changed +22 -2
src/browser/__tests__/ReactBrowserEventEmitter-test.js
+12
@@ -57,6 +57,7 @@ var LISTENER = mocks.getMockFunction();
57 var ON_CLICK_KEY = keyOf({onClick: null});
58 var ON_TOUCH_TAP_KEY = keyOf({onTouchTap: null});
59 var ON_CHANGE_KEY = keyOf({onChange: null});
60 +var ON_MOUSE_ENTER_KEY = keyOf({onMouseEnter: null});
61
62
63 /**
@@ -320,6 +321,17 @@ describe('ReactBrowserEventEmitter', function() {
321 expect(handleParentClick.mock.calls.length).toBe(0);
322 });
323
324 + it('should have mouse enter simulated by test utils', function() {
325 + ReactBrowserEventEmitter.putListener(
326 + getID(CHILD),
327 + ON_MOUSE_ENTER_KEY,
328 + recordID.bind(null, getID(CHILD))
329 + );
330 + ReactTestUtils.Simulate.mouseEnter(CHILD);
331 + expect(idCallOrder.length).toBe(1);
332 + expect(idCallOrder[0]).toBe(getID(CHILD));
333 + });
334 +
335 it('should infer onTouchTap from a touchStart/End', function() {
336 ReactBrowserEventEmitter.putListener(
337 getID(CHILD),
src/test/ReactTestUtils.js
+10 -2
@@ -398,17 +398,25 @@ function makeSimulator(eventType) {
398 node = domComponentOrNode;
399 }
400
401 + var dispatchConfig =
402 + ReactBrowserEventEmitter.eventNameDispatchConfigs[eventType];
403 +
404 var fakeNativeEvent = new Event();
405 fakeNativeEvent.target = node;
406 // We don't use SyntheticEvent.getPooled in order to not have to worry about
407 // properly destroying any properties assigned from `eventData` upon release
408 var event = new SyntheticEvent(
406 - ReactBrowserEventEmitter.eventNameDispatchConfigs[eventType],
409 + dispatchConfig,
410 ReactMount.getID(node),
411 fakeNativeEvent
412 );
413 assign(event, eventData);
411 - EventPropagators.accumulateTwoPhaseDispatches(event);
414 +
415 + if (dispatchConfig.phasedRegistrationNames) {
416 + EventPropagators.accumulateTwoPhaseDispatches(event);
417 + } else {
418 + EventPropagators.accumulateDirectDispatches(event);
419 + }
420
421 ReactUpdates.batchedUpdates(function() {
422 EventPluginHub.enqueueEvents(event);