main
js 67 lines 1.48 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @emails react-core
8 */
9
10 'use strict';
11
12 /**
13 * Change environment support for PointerEvent.
14 */
15
16 function emptyFunction() {}
17
18 export function hasPointerEvent() {
19 return global != null && global.PointerEvent != null;
20 }
21
22 export function setPointerEvent(bool) {
23 const pointerCaptureFn = name => id => {
24 if (typeof id !== 'number') {
25 if (__DEV__) {
26 console.error('A pointerId must be passed to "%s"', name);
27 }
28 }
29 };
30 global.PointerEvent = bool ? emptyFunction : undefined;
31 global.HTMLElement.prototype.setPointerCapture = bool
32 ? pointerCaptureFn('setPointerCapture')
33 : undefined;
34 global.HTMLElement.prototype.releasePointerCapture = bool
35 ? pointerCaptureFn('releasePointerCapture')
36 : undefined;
37 }
38
39 /**
40 * Change environment host platform.
41 */
42
43 const platformGetter = jest.spyOn(global.navigator, 'platform', 'get');
44
45 export const platform = {
46 clear() {
47 platformGetter.mockClear();
48 },
49 get() {
50 return global.navigator.platform === 'MacIntel' ? 'mac' : 'windows';
51 },
52 set(name: 'mac' | 'windows') {
53 switch (name) {
54 case 'mac': {
55 platformGetter.mockReturnValue('MacIntel');
56 break;
57 }
58 case 'windows': {
59 platformGetter.mockReturnValue('Win32');
60 break;
61 }
62 default: {
63 break;
64 }
65 }
66 },
67 };