Skip to content

Commit 4fa58a7

Browse files
committed
self code review
1 parent 04b42b4 commit 4fa58a7

File tree

8 files changed

+32
-32
lines changed

8 files changed

+32
-32
lines changed

src/event-builder/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ export function buildTouchEvent() {
99
return {
1010
...baseSyntheticEvent(),
1111
nativeEvent: {
12-
changedTouches: [] as number[],
12+
changedTouches: [] as unknown[],
1313
identifier: 0,
1414
locationX: 0,
1515
locationY: 0,
1616
pageX: 0,
1717
pageY: 0,
1818
target: 0,
1919
timestamp: Date.now(),
20-
touches: [] as number[],
20+
touches: [] as unknown[],
2121
},
2222
currentTarget: { measure: () => {} },
2323
};

src/event-builder/types.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/fire-event.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import type { Fiber, HostElement } from 'test-renderer';
99

1010
import { act } from './act';
1111
import { buildScrollEvent, buildTouchEvent } from './event-builder';
12-
import type { Point } from './event-builder/types';
1312
import type { EventHandler } from './event-handler';
1413
import { getEventHandlerFromProps } from './event-handler';
1514
import { isElementMounted } from './helpers/component-tree';
1615
import { isHostScrollView, isHostTextInput } from './helpers/host-component-names';
1716
import { isPointerEventEnabled } from './helpers/pointer-events';
1817
import { isEditableTextInput } from './helpers/text-input';
1918
import { nativeState } from './native-state';
20-
import type { StringWithAutocomplete } from './types';
19+
import type { Point, StringWithAutocomplete } from './types';
2120

2221
function isTouchResponder(element: HostElement) {
2322
return Boolean(element.props.onStartShouldSetResponder) || isHostTextInput(element);
@@ -215,7 +214,7 @@ function mergeEventProps(target: Record<string, unknown>, source: Record<string,
215214
const sourceValue = source[key];
216215
const targetValue = target[key];
217216
if (
218-
sourceValue &&
217+
sourceValue != null &&
219218
typeof sourceValue === 'object' &&
220219
!Array.isArray(sourceValue) &&
221220
targetValue &&

src/native-state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { HostElement } from 'test-renderer';
22

3-
import type { Point } from './event-builder/types';
3+
import type { Point } from './types';
44

55
/**
66
* Simulated native state for unmanaged controls.

src/types.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ export type RefObject<T> = {
33
current: T;
44
};
55

6+
/**
7+
* Location of an element.
8+
*/
9+
export interface Point {
10+
y: number;
11+
x: number;
12+
}
13+
14+
/**
15+
* Size of an element.
16+
*/
17+
export interface Size {
18+
height: number;
19+
width: number;
20+
}
21+
22+
/**
23+
* Range of text in a text input.
24+
*/
25+
export interface TextRange {
26+
start: number;
27+
end: number;
28+
}
29+
630
// TS autocomplete trick
731
// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939
832
export type StringWithAutocomplete<T> = T | (string & {});

src/user-event/scroll/scroll-to.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { stringify } from 'jest-matcher-utils';
22
import type { HostElement } from 'test-renderer';
33

44
import { buildScrollEvent } from '../../event-builder';
5-
import type { Point, Size } from '../../event-builder/types';
65
import { ErrorWithStack } from '../../helpers/errors';
76
import { isHostScrollView } from '../../helpers/host-component-names';
87
import { pick } from '../../helpers/object';
98
import { nativeState } from '../../native-state';
9+
import type { Point, Size } from '../../types';
1010
import type { UserEventConfig, UserEventInstance } from '../setup';
1111
import { dispatchEvent, wait } from '../utils';
1212
import { createScrollSteps, inertialInterpolator, linearInterpolator } from './utils';

src/user-event/scroll/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Point } from '../../event-builder/types';
1+
import type { Point } from '../../types';
22

33
const DEFAULT_STEPS_COUNT = 5;
44

src/user-event/utils/content-size.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Size } from '../../event-builder/types';
1+
import type { Size } from '../../types';
22

33
/**
44
* Simple function for getting mock the size of given text.

0 commit comments

Comments
 (0)