mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Moves the unit testing library for events into the `packages` directory so it can more easily be used in tests for other react packages, and mirrored internally to help with testing of event hooks we prototype in www.
36 lines
934 B
JavaScript
36 lines
934 B
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @emails react-core
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import {hasPointerEvent, setPointerEvent} from './domEnvironment';
|
|
|
|
export function describeWithPointerEvent(message, describeFn) {
|
|
const pointerEvent = 'PointerEvent';
|
|
const fallback = 'MouseEvent/TouchEvent';
|
|
describe.each`
|
|
value | name
|
|
${true} | ${pointerEvent}
|
|
${false} | ${fallback}
|
|
`(`${message}: $name`, entry => {
|
|
const hasPointerEvents = entry.value;
|
|
setPointerEvent(hasPointerEvents);
|
|
describeFn(hasPointerEvents);
|
|
});
|
|
}
|
|
|
|
export function testWithPointerType(message, testFn) {
|
|
const table = hasPointerEvent()
|
|
? ['mouse', 'touch', 'pen']
|
|
: ['mouse', 'touch'];
|
|
test.each(table)(`${message}: %s`, pointerType => {
|
|
testFn(pointerType);
|
|
});
|
|
}
|