dillon1000/react
Commit
Browse files [react-events] DOM event testing library (#16433)
This patch formalizes the mock native events and event sequences used in unit tests.
The `createEventTarget` function returns an object that can be used to dispatch native event sequences on the target without having to manually do so across all the scenarios we need to account for. Unit tests can be written as if we were only working with PointerEvent, but they will dispatch realistic native event sequences based on the execution environment (e.g., is PointerEvent supported?) and pointer type.
```
describe.each(environments)('Suite', (hasPointerEvents) => {
beforeEach(() => {
// setup
});
test.each(pointerTypes)('Test', (pointerType) => {
const target = createEventTarget(node);
target.pointerdown({pointerType});
expect(callback).toBeCalled();
});
});
```
Every native event that is dispatched now includes a complete object by default. The properties of the events can be customized. Properties that shouldn't be relied on in responder implementations are excluded from the mock native events to ensure tests will fail. Equivalent properties are normalized across different event types, e.g., 'pointerId' is converted to 'identifier' before a TouchEvent is dispatched.Changed paths14 files
First-parent comparisonpackages/react-events/src/dom/Press.js ModifiedM packages/react-events/src/dom/Scroll.js ModifiedM packages/react-events/src/dom/__tests__/ContextMenu-test.internal.js ModifiedM packages/react-events/src/dom/__tests__/Focus-test.internal.js ModifiedM packages/react-events/src/dom/__tests__/FocusWithin-test.internal.js ModifiedM packages/react-events/src/dom/__tests__/Hover-test.internal.js ModifiedM packages/react-events/src/dom/__tests__/Keyboard-test.internal.js ModifiedM packages/react-events/src/dom/__tests__/Press-test.internal.js ModifiedM packages/react-events/src/dom/__tests__/Scroll-test.internal.js ModifiedD packages/react-events/src/dom/test-utils.js DeletedA packages/react-events/src/dom/testing-library/domEnvironment.js AddedA packages/react-events/src/dom/testing-library/domEventSequences.js AddedA packages/react-events/src/dom/testing-library/domEvents.js AddedA packages/react-events/src/dom/testing-library/index.js AddedPatch
Files changed
Rendering syntax-highlighted changes…