Skip to content

fix: user event add target prop #1538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 30, 2023
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
48 changes: 48 additions & 0 deletions src/user-event/__tests__/__snapshots__/clear.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,46 @@ exports[`clear() supports basic case: value: "Hello! 1`] = `
{
"name": "focus",
"payload": {
"currentTarget": {},
"nativeEvent": {
"target": 0,
},
"target": {},
},
},
{
"name": "selectionChange",
"payload": {
"currentTarget": {},
"nativeEvent": {
"selection": {
"end": 6,
"start": 0,
},
},
"target": {},
},
},
{
"name": "keyPress",
"payload": {
"currentTarget": {},
"nativeEvent": {
"key": "Backspace",
},
"target": {},
},
},
{
"name": "change",
"payload": {
"currentTarget": {},
"nativeEvent": {
"eventCount": 0,
"target": 0,
"text": "",
},
"target": {},
},
},
{
Expand All @@ -46,29 +54,35 @@ exports[`clear() supports basic case: value: "Hello! 1`] = `
{
"name": "selectionChange",
"payload": {
"currentTarget": {},
"nativeEvent": {
"selection": {
"end": 0,
"start": 0,
},
},
"target": {},
},
},
{
"name": "endEditing",
"payload": {
"currentTarget": {},
"nativeEvent": {
"target": 0,
"text": "",
},
"target": {},
},
},
{
"name": "blur",
"payload": {
"currentTarget": {},
"nativeEvent": {
"target": 0,
},
"target": {},
},
},
]
Expand All @@ -79,38 +93,46 @@ exports[`clear() supports defaultValue prop: defaultValue: "Hello Default!" 1`]
{
"name": "focus",
"payload": {
"currentTarget": {},
"nativeEvent": {
"target": 0,
},
"target": {},
},
},
{
"name": "selectionChange",
"payload": {
"currentTarget": {},
"nativeEvent": {
"selection": {
"end": 14,
"start": 0,
},
},
"target": {},
},
},
{
"name": "keyPress",
"payload": {
"currentTarget": {},
"nativeEvent": {
"key": "Backspace",
},
"target": {},
},
},
{
"name": "change",
"payload": {
"currentTarget": {},
"nativeEvent": {
"eventCount": 0,
"target": 0,
"text": "",
},
"target": {},
},
},
{
Expand All @@ -120,29 +142,35 @@ exports[`clear() supports defaultValue prop: defaultValue: "Hello Default!" 1`]
{
"name": "selectionChange",
"payload": {
"currentTarget": {},
"nativeEvent": {
"selection": {
"end": 0,
"start": 0,
},
},
"target": {},
},
},
{
"name": "endEditing",
"payload": {
"currentTarget": {},
"nativeEvent": {
"target": 0,
"text": "",
},
"target": {},
},
},
{
"name": "blur",
"payload": {
"currentTarget": {},
"nativeEvent": {
"target": 0,
},
"target": {},
},
},
]
Expand All @@ -154,33 +182,40 @@ How are you?" multiline: true, 1`] = `
{
"name": "focus",
"payload": {
"currentTarget": {},
"nativeEvent": {
"target": 0,
},
"target": {},
},
},
{
"name": "selectionChange",
"payload": {
"currentTarget": {},
"nativeEvent": {
"selection": {
"end": 25,
"start": 0,
},
},
"target": {},
},
},
{
"name": "keyPress",
"payload": {
"currentTarget": {},
"nativeEvent": {
"key": "Backspace",
},
"target": {},
},
},
{
"name": "textInput",
"payload": {
"currentTarget": {},
"nativeEvent": {
"previousText": "Hello World!
How are you?",
Expand All @@ -191,16 +226,19 @@ How are you?",
"target": 0,
"text": "",
},
"target": {},
},
},
{
"name": "change",
"payload": {
"currentTarget": {},
"nativeEvent": {
"eventCount": 0,
"target": 0,
"text": "",
},
"target": {},
},
},
{
Expand All @@ -210,41 +248,49 @@ How are you?",
{
"name": "selectionChange",
"payload": {
"currentTarget": {},
"nativeEvent": {
"selection": {
"end": 0,
"start": 0,
},
},
"target": {},
},
},
{
"name": "contentSizeChange",
"payload": {
"currentTarget": {},
"nativeEvent": {
"contentSize": {
"height": 16,
"width": 0,
},
"target": 0,
},
"target": {},
},
},
{
"name": "endEditing",
"payload": {
"currentTarget": {},
"nativeEvent": {
"target": 0,
"text": "",
},
"target": {},
},
},
{
"name": "blur",
"payload": {
"currentTarget": {},
"nativeEvent": {
"target": 0,
},
"target": {},
},
},
]
Expand All @@ -259,10 +305,12 @@ exports[`clear() works when not all events have handlers 1`] = `
{
"name": "endEditing",
"payload": {
"currentTarget": {},
"nativeEvent": {
"target": 0,
"text": "",
},
"target": {},
},
},
]
Expand Down
9 changes: 7 additions & 2 deletions src/user-event/event-builder/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
function touch() {
return {
persist: jest.fn(),
currentTarget: { measure: jest.fn() },
nativeEvent: {
changedTouches: [],
identifier: 0,
Expand All @@ -18,6 +16,9 @@ function touch() {
timestamp: Date.now(),
touches: [],
},
persist: jest.fn(),
currentTarget: { measure: jest.fn() },
target: {},
};
}

Expand Down Expand Up @@ -48,6 +49,8 @@ export const CommonEventBuilder = {
nativeEvent: {
target: 0,
},
currentTarget: {},
target: {},
};
},

Expand All @@ -61,6 +64,8 @@ export const CommonEventBuilder = {
nativeEvent: {
target: 0,
},
currentTarget: {},
target: {},
};
},
};
2 changes: 2 additions & 0 deletions src/user-event/event-builder/scroll-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const ScrollViewEventBuilder = {
target: 0,
velocity: { y: 0, x: 0 },
},
currentTarget: {},
target: {},
};
},
};
14 changes: 14 additions & 0 deletions src/user-event/event-builder/text-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const TextInputEventBuilder = {
change: (text: string) => {
return {
nativeEvent: { text, target: 0, eventCount: 0 },
currentTarget: {},
target: {},
};
},

Expand All @@ -21,6 +23,8 @@ export const TextInputEventBuilder = {
keyPress: (key: string) => {
return {
nativeEvent: { key },
currentTarget: {},
target: {},
};
},

Expand All @@ -32,6 +36,8 @@ export const TextInputEventBuilder = {
submitEditing: (text: string) => {
return {
nativeEvent: { text, target: 0 },
currentTarget: {},
target: {},
};
},

Expand All @@ -43,6 +49,8 @@ export const TextInputEventBuilder = {
endEditing: (text: string) => {
return {
nativeEvent: { text, target: 0 },
currentTarget: {},
target: {},
};
},

Expand All @@ -54,6 +62,8 @@ export const TextInputEventBuilder = {
selectionChange: ({ start, end }: TextRange) => {
return {
nativeEvent: { selection: { start, end } },
currentTarget: {},
target: {},
};
},

Expand All @@ -70,6 +80,8 @@ export const TextInputEventBuilder = {
range: { start: text.length, end: text.length },
target: 0,
},
currentTarget: {},
target: {},
};
},

Expand All @@ -81,6 +93,8 @@ export const TextInputEventBuilder = {
contentSizeChange: ({ width, height }: ContentSize) => {
return {
nativeEvent: { contentSize: { width, height }, target: 0 },
currentTarget: {},
target: {},
};
},
};
Loading