Skip to content
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
8 changes: 8 additions & 0 deletions packages/react-dom/src/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ describe('ReactTestUtils', () => {
ReactTestUtils = require('react-dom/test-utils');
});

it('Simulate should have locally attached media events', () => {
expect(Object.keys(ReactTestUtils.Simulate).sort()).toMatchSnapshot();
});

it('SimulateNative should have locally attached media events', () => {
expect(Object.keys(ReactTestUtils.SimulateNative).sort()).toMatchSnapshot();
});

it('gives Jest mocks a passthrough implementation with mockComponent()', () => {
class MockedComponent extends React.Component {
render() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ReactTestUtils Simulate should have locally attached media events 1`] = `
Array [
"abort",
"animationEnd",
"animationIteration",
"animationStart",
"beforeInput",
"blur",
"canPlay",
"canPlayThrough",
"cancel",
"change",
"click",
"close",
"compositionEnd",
"compositionStart",
"compositionUpdate",
"contextMenu",
"copy",
"cut",
"doubleClick",
"drag",
"dragEnd",
"dragEnter",
"dragExit",
"dragLeave",
"dragOver",
"dragStart",
"drop",
"durationChange",
"emptied",
"encrypted",
"ended",
"error",
"focus",
"input",
"invalid",
"keyDown",
"keyPress",
"keyUp",
"load",
"loadStart",
"loadedData",
"loadedMetadata",
"mouseDown",
"mouseEnter",
"mouseLeave",
"mouseMove",
"mouseOut",
"mouseOver",
"mouseUp",
"paste",
"pause",
"play",
"playing",
"progress",
"rateChange",
"reset",
"scroll",
"seeked",
"seeking",
"select",
"stalled",
"submit",
"suspend",
"timeUpdate",
"toggle",
"touchCancel",
"touchEnd",
"touchMove",
"touchStart",
"transitionEnd",
"volumeChange",
"waiting",
"wheel",
]
`;

exports[`ReactTestUtils SimulateNative should have locally attached media events 1`] = `
Array [
"abort",
"animationEnd",
"animationIteration",
"animationStart",
"blur",
"canPlay",
"canPlayThrough",
"cancel",
"change",
"click",
"close",
"compositionEnd",
"compositionStart",
"compositionUpdate",
"contextMenu",
"copy",
"cut",
"doubleClick",
"drag",
"dragEnd",
"dragEnter",
"dragExit",
"dragLeave",
"dragOver",
"dragStart",
"drop",
"durationChange",
"emptied",
"encrypted",
"ended",
"error",
"focus",
"input",
"keyDown",
"keyPress",
"keyUp",
"load",
"loadStart",
"loadedData",
"loadedMetadata",
"mouseDown",
"mouseMove",
"mouseOut",
"mouseOver",
"mouseUp",
"paste",
"pause",
"play",
"playing",
"progress",
"rateChange",
"scroll",
"seeked",
"seeking",
"selectionChange",
"stalled",
"suspend",
"textInput",
"timeUpdate",
"toggle",
"touchCancel",
"touchEnd",
"touchMove",
"touchStart",
"transitionEnd",
"volumeChange",
"waiting",
"wheel",
]
`;
9 changes: 7 additions & 2 deletions packages/react-dom/src/test-utils/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import SyntheticEvent from 'events/SyntheticEvent';
import invariant from 'fbjs/lib/invariant';

import {topLevelTypes} from '../events/BrowserEventConstants';
import {topLevelTypes, mediaEventTypes} from '../events/BrowserEventConstants';

const {findDOMNode} = ReactDOM;
const {
Expand Down Expand Up @@ -456,7 +456,12 @@ function makeNativeSimulator(eventType) {
};
}

Object.keys(topLevelTypes).forEach(function(eventType) {
const eventKeys = [].concat(
Object.keys(topLevelTypes),
Object.keys(mediaEventTypes),
);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use EventPluginRegistry.eventNameDispatchConfigs for SimulateNative, but it:

  1. Does not include invalid, mouseEnter, mouseLeave, reset, select, or submit.
  2. Adds selectionChange, textInput

Curiously, this is the case for ReactTestUtils.Simulate. Is this correct?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever’s currently there is “correct” in the sense that we shouldn’t change it now, and we should remove SimilateNative altogether in 17.


eventKeys.forEach(function(eventType) {
// Event type is stored as 'topClick' - we transform that to 'click'
const convenienceName =
eventType.indexOf('top') === 0
Expand Down