diff --git a/src/user-event/__tests__/__snapshots__/clear.test.tsx.snap b/src/user-event/__tests__/__snapshots__/clear.test.tsx.snap index c0d849e4c..7ac08d0b5 100644 --- a/src/user-event/__tests__/__snapshots__/clear.test.tsx.snap +++ b/src/user-event/__tests__/__snapshots__/clear.test.tsx.snap @@ -6,45 +6,73 @@ exports[`clear() supports basic case: value: "Hello! 1`] = ` "name": "focus", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 6, "start": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "Backspace", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -55,34 +83,55 @@ exports[`clear() supports basic case: value: "Hello! 1`] = ` "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 0, "start": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": "", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "blur", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] @@ -94,45 +143,73 @@ exports[`clear() supports defaultValue prop: defaultValue: "Hello Default!" 1`] "name": "focus", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 14, "start": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "Backspace", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -143,34 +220,55 @@ exports[`clear() supports defaultValue prop: defaultValue: "Hello Default!" 1`] "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 0, "start": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": "", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "blur", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] @@ -183,39 +281,63 @@ How are you?" multiline: true, 1`] = ` "name": "focus", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 25, "start": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "Backspace", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "textInput", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "previousText": "Hello World! How are you?", @@ -226,19 +348,30 @@ How are you?", "target": 0, "text": "", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -249,19 +382,29 @@ How are you?", "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 0, "start": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "contentSizeChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentSize": { "height": 16, @@ -269,28 +412,46 @@ How are you?", }, "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": "", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "blur", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] @@ -306,11 +467,18 @@ exports[`clear() works when not all events have handlers 1`] = ` "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": "", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] diff --git a/src/user-event/event-builder/base.ts b/src/user-event/event-builder/base.ts new file mode 100644 index 000000000..0de21e8b7 --- /dev/null +++ b/src/user-event/event-builder/base.ts @@ -0,0 +1,17 @@ +import { BaseSyntheticEvent } from 'react'; + +/** Builds base syntentic event stub, with prop values as inspected in RN runtime. */ +export function baseSyntheticEvent(): Partial> { + return { + currentTarget: {}, + target: {}, + preventDefault: () => {}, + isDefaultPrevented: () => false, + stopPropagation: () => {}, + isPropagationStopped: () => false, + persist: () => {}, + // @ts-expect-error: `isPersistent` is not a standard prop, but it's used in RN runtime. See: https://react.dev/reference/react-dom/components/common#react-event-object-methods + isPersistent: () => false, + timeStamp: 0, + }; +} diff --git a/src/user-event/event-builder/common.ts b/src/user-event/event-builder/common.ts index f52b2a082..173c8ec7e 100644 --- a/src/user-event/event-builder/common.ts +++ b/src/user-event/event-builder/common.ts @@ -1,3 +1,5 @@ +import { baseSyntheticEvent } from './base'; + /** * Experimental values: * - iOS: `{"changedTouches": [[Circular]], "identifier": 1, "locationX": 253, "locationY": 30.333328247070312, "pageX": 273, "pageY": 141.3333282470703, "target": 75, "timestamp": 875928682.0450834, "touches": [[Circular]]}` @@ -5,6 +7,7 @@ */ function touch() { return { + ...baseSyntheticEvent(), nativeEvent: { changedTouches: [], identifier: 0, @@ -16,9 +19,7 @@ function touch() { timestamp: Date.now(), touches: [], }, - persist: () => {}, currentTarget: { measure: () => {} }, - target: {}, }; } @@ -46,11 +47,10 @@ export const CommonEventBuilder = { */ focus: () => { return { + ...baseSyntheticEvent(), nativeEvent: { target: 0, }, - currentTarget: {}, - target: {}, }; }, @@ -61,11 +61,10 @@ export const CommonEventBuilder = { */ blur: () => { return { + ...baseSyntheticEvent(), nativeEvent: { target: 0, }, - currentTarget: {}, - target: {}, }; }, }; diff --git a/src/user-event/event-builder/scroll-view.ts b/src/user-event/event-builder/scroll-view.ts index 4bae5aa19..c477b6c29 100644 --- a/src/user-event/event-builder/scroll-view.ts +++ b/src/user-event/event-builder/scroll-view.ts @@ -1,3 +1,5 @@ +import { baseSyntheticEvent } from './base'; + /** * Scroll position of a scrollable element. */ @@ -28,6 +30,7 @@ export type ScrollEventOptions = { export const ScrollViewEventBuilder = { scroll: (offset: ContentOffset = { y: 0, x: 0 }, options?: ScrollEventOptions) => { return { + ...baseSyntheticEvent(), nativeEvent: { contentInset: { bottom: 0, left: 0, right: 0, top: 0 }, contentOffset: { y: offset.y, x: offset.x }, @@ -43,8 +46,6 @@ export const ScrollViewEventBuilder = { target: 0, velocity: { y: 0, x: 0 }, }, - currentTarget: {}, - target: {}, }; }, }; diff --git a/src/user-event/event-builder/text-input.ts b/src/user-event/event-builder/text-input.ts index b0d215235..89a45a340 100644 --- a/src/user-event/event-builder/text-input.ts +++ b/src/user-event/event-builder/text-input.ts @@ -1,5 +1,6 @@ import { ContentSize } from '../utils/content-size'; import { TextRange } from '../utils/text-range'; +import { baseSyntheticEvent } from './base'; export const TextInputEventBuilder = { /** @@ -9,9 +10,8 @@ export const TextInputEventBuilder = { */ change: (text: string) => { return { + ...baseSyntheticEvent(), nativeEvent: { text, target: 0, eventCount: 0 }, - currentTarget: {}, - target: {}, }; }, @@ -22,9 +22,8 @@ export const TextInputEventBuilder = { */ keyPress: (key: string) => { return { + ...baseSyntheticEvent(), nativeEvent: { key }, - currentTarget: {}, - target: {}, }; }, @@ -35,9 +34,8 @@ export const TextInputEventBuilder = { */ submitEditing: (text: string) => { return { + ...baseSyntheticEvent(), nativeEvent: { text, target: 0 }, - currentTarget: {}, - target: {}, }; }, @@ -48,9 +46,8 @@ export const TextInputEventBuilder = { */ endEditing: (text: string) => { return { + ...baseSyntheticEvent(), nativeEvent: { text, target: 0 }, - currentTarget: {}, - target: {}, }; }, @@ -61,9 +58,8 @@ export const TextInputEventBuilder = { */ selectionChange: ({ start, end }: TextRange) => { return { + ...baseSyntheticEvent(), nativeEvent: { selection: { start, end } }, - currentTarget: {}, - target: {}, }; }, @@ -74,14 +70,13 @@ export const TextInputEventBuilder = { */ textInput: (text: string, previousText: string) => { return { + ...baseSyntheticEvent(), nativeEvent: { text, previousText, range: { start: text.length, end: text.length }, target: 0, }, - currentTarget: {}, - target: {}, }; }, @@ -92,9 +87,8 @@ export const TextInputEventBuilder = { */ contentSizeChange: ({ width, height }: ContentSize) => { return { + ...baseSyntheticEvent(), nativeEvent: { contentSize: { width, height }, target: 0 }, - currentTarget: {}, - target: {}, }; }, }; diff --git a/src/user-event/press/__tests__/__snapshots__/longPress.test.tsx.snap b/src/user-event/press/__tests__/__snapshots__/longPress.test.tsx.snap index 7ff43a1bf..fa31b7a34 100644 --- a/src/user-event/press/__tests__/__snapshots__/longPress.test.tsx.snap +++ b/src/user-event/press/__tests__/__snapshots__/longPress.test.tsx.snap @@ -11,6 +11,9 @@ exports[`userEvent.longPress with fake timers calls onLongPress if the delayLong "dispatchConfig": { "registrationName": "onResponderGrant", }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -23,7 +26,10 @@ exports[`userEvent.longPress with fake timers calls onLongPress if the delayLong "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] diff --git a/src/user-event/press/__tests__/__snapshots__/press.test.tsx.snap b/src/user-event/press/__tests__/__snapshots__/press.test.tsx.snap index 48c109876..ceb2803f3 100644 --- a/src/user-event/press/__tests__/__snapshots__/press.test.tsx.snap +++ b/src/user-event/press/__tests__/__snapshots__/press.test.tsx.snap @@ -11,6 +11,9 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu "dispatchConfig": { "registrationName": "onResponderGrant", }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -23,7 +26,10 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -35,6 +41,9 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu "dispatchConfig": { "registrationName": "onResponderRelease", }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -47,7 +56,10 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -59,6 +71,9 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu "dispatchConfig": { "registrationName": "onResponderRelease", }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -71,7 +86,10 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] diff --git a/src/user-event/scroll/__tests__/__snapshots__/scroll-to-flat-list.test.tsx.snap b/src/user-event/scroll/__tests__/__snapshots__/scroll-to-flat-list.test.tsx.snap index d8131e435..faa7ee49d 100644 --- a/src/user-event/scroll/__tests__/__snapshots__/scroll-to-flat-list.test.tsx.snap +++ b/src/user-event/scroll/__tests__/__snapshots__/scroll-to-flat-list.test.tsx.snap @@ -6,6 +6,9 @@ exports[`scrollTo() with FlatList supports vertical drag scroll: scrollTo({ y: 1 "name": "scrollBeginDrag", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentInset": { "bottom": 0, @@ -32,13 +35,20 @@ exports[`scrollTo() with FlatList supports vertical drag scroll: scrollTo({ y: 1 "y": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "scroll", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentInset": { "bottom": 0, @@ -65,13 +75,20 @@ exports[`scrollTo() with FlatList supports vertical drag scroll: scrollTo({ y: 1 "y": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "scroll", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentInset": { "bottom": 0, @@ -98,13 +115,20 @@ exports[`scrollTo() with FlatList supports vertical drag scroll: scrollTo({ y: 1 "y": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "scroll", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentInset": { "bottom": 0, @@ -131,13 +155,20 @@ exports[`scrollTo() with FlatList supports vertical drag scroll: scrollTo({ y: 1 "y": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "scrollEndDrag", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentInset": { "bottom": 0, @@ -164,7 +195,11 @@ exports[`scrollTo() with FlatList supports vertical drag scroll: scrollTo({ y: 1 "y": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] diff --git a/src/user-event/scroll/__tests__/__snapshots__/scroll-to.test.tsx.snap b/src/user-event/scroll/__tests__/__snapshots__/scroll-to.test.tsx.snap index 7055f54c8..60fac01aa 100644 --- a/src/user-event/scroll/__tests__/__snapshots__/scroll-to.test.tsx.snap +++ b/src/user-event/scroll/__tests__/__snapshots__/scroll-to.test.tsx.snap @@ -6,6 +6,9 @@ exports[`scrollTo() supports vertical drag scroll: scrollTo({ y: 100 }) 1`] = ` "name": "scrollBeginDrag", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentInset": { "bottom": 0, @@ -32,13 +35,20 @@ exports[`scrollTo() supports vertical drag scroll: scrollTo({ y: 100 }) 1`] = ` "y": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "scroll", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentInset": { "bottom": 0, @@ -65,13 +75,20 @@ exports[`scrollTo() supports vertical drag scroll: scrollTo({ y: 100 }) 1`] = ` "y": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "scroll", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentInset": { "bottom": 0, @@ -98,13 +115,20 @@ exports[`scrollTo() supports vertical drag scroll: scrollTo({ y: 100 }) 1`] = ` "y": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "scroll", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentInset": { "bottom": 0, @@ -131,13 +155,20 @@ exports[`scrollTo() supports vertical drag scroll: scrollTo({ y: 100 }) 1`] = ` "y": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "scrollEndDrag", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentInset": { "bottom": 0, @@ -164,7 +195,11 @@ exports[`scrollTo() supports vertical drag scroll: scrollTo({ y: 100 }) 1`] = ` "y": 0, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] diff --git a/src/user-event/type/__tests__/__snapshots__/type-managed.test.tsx.snap b/src/user-event/type/__tests__/__snapshots__/type-managed.test.tsx.snap index 6fad62214..ac3a21865 100644 --- a/src/user-event/type/__tests__/__snapshots__/type-managed.test.tsx.snap +++ b/src/user-event/type/__tests__/__snapshots__/type-managed.test.tsx.snap @@ -8,6 +8,9 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = ` "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -20,17 +23,27 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = ` "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "focus", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -39,6 +52,9 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = ` "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -51,29 +67,46 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = ` "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "W", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "W", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -84,35 +117,56 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = ` "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 1, "start": 1, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "o", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "Wo", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -123,35 +177,56 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = ` "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 2, "start": 2, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "w", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "Wow", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -162,34 +237,55 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = ` "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 3, "start": 3, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": "Wow", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "blur", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] @@ -203,6 +299,9 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC" "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -215,17 +314,27 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC" "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "focus", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -234,6 +343,9 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC" "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -246,29 +358,46 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC" "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "A", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "XXXA", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -279,35 +408,56 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC" "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 4, "start": 4, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "B", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "XXXB", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -318,35 +468,56 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC" "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 4, "start": 4, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "C", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "XXXC", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -357,34 +528,55 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC" "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 4, "start": 4, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": "XXX", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "blur", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] diff --git a/src/user-event/type/__tests__/__snapshots__/type.test.tsx.snap b/src/user-event/type/__tests__/__snapshots__/type.test.tsx.snap index 8873df672..b75157f8f 100644 --- a/src/user-event/type/__tests__/__snapshots__/type.test.tsx.snap +++ b/src/user-event/type/__tests__/__snapshots__/type.test.tsx.snap @@ -8,6 +8,9 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1 "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -20,17 +23,27 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1 "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "focus", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -39,6 +52,9 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1 "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -51,29 +67,46 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1 "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "Backspace", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "xx", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -84,35 +117,56 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1 "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 2, "start": 2, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "a", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "xxa", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -123,34 +177,55 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1 "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 3, "start": 3, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": "xxa", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "blur", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] @@ -164,6 +239,9 @@ exports[`type() supports basic case: input: "abc" 1`] = ` "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -176,17 +254,27 @@ exports[`type() supports basic case: input: "abc" 1`] = ` "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "focus", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -195,6 +283,9 @@ exports[`type() supports basic case: input: "abc" 1`] = ` "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -207,29 +298,46 @@ exports[`type() supports basic case: input: "abc" 1`] = ` "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "a", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "a", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -240,35 +348,56 @@ exports[`type() supports basic case: input: "abc" 1`] = ` "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 1, "start": 1, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "b", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "ab", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -279,35 +408,56 @@ exports[`type() supports basic case: input: "abc" 1`] = ` "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 2, "start": 2, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "c", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "abc", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -318,34 +468,55 @@ exports[`type() supports basic case: input: "abc" 1`] = ` "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 3, "start": 3, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": "abc", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "blur", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] @@ -359,6 +530,9 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`] "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -371,17 +545,27 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`] "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "focus", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -390,6 +574,9 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`] "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -402,29 +589,46 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`] "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "a", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "xxxa", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -435,35 +639,56 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`] "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 4, "start": 4, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "b", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": "xxxab", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -474,34 +699,55 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`] "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 5, "start": 5, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": "xxxab", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "blur", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] @@ -515,6 +761,9 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -527,17 +776,27 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "focus", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -546,6 +805,9 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` "currentTarget": { "measure": [Function], }, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "changedTouches": [], "identifier": 0, @@ -558,23 +820,36 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` "touches": [], }, "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "Enter", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "textInput", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "previousText": "", "range": { @@ -585,20 +860,31 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` "text": " ", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, "text": " ", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -610,19 +896,29 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 1, "start": 1, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "contentSizeChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentSize": { "height": 32, @@ -630,23 +926,37 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` }, "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "keyPress", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "key": "Enter", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "textInput", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "previousText": " ", @@ -659,13 +969,20 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` ", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "change", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "eventCount": 0, "target": 0, @@ -673,7 +990,11 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` ", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { @@ -686,19 +1007,29 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` "name": "selectionChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "selection": { "end": 2, "start": 2, }, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "contentSizeChange", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "contentSize": { "height": 48, @@ -706,30 +1037,48 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = ` }, "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": " ", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, { "name": "blur", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] @@ -753,11 +1102,18 @@ exports[`type() works when not all events have handlers: input: "abc" 1`] = ` "name": "endEditing", "payload": { "currentTarget": {}, + "isDefaultPrevented": [Function], + "isPersistent": [Function], + "isPropagationStopped": [Function], "nativeEvent": { "target": 0, "text": "abc", }, + "persist": [Function], + "preventDefault": [Function], + "stopPropagation": [Function], "target": {}, + "timeStamp": 0, }, }, ] diff --git a/src/user-event/type/__tests__/type.test.tsx b/src/user-event/type/__tests__/type.test.tsx index ad3564724..4918e3f2a 100644 --- a/src/user-event/type/__tests__/type.test.tsx +++ b/src/user-event/type/__tests__/type.test.tsx @@ -242,7 +242,7 @@ describe('type()', () => { ]); expect(events[7].name).toBe('submitEditing'); - expect(events[7].payload).toEqual({ + expect(events[7].payload).toMatchObject({ nativeEvent: { text: 'a', target: 0 }, currentTarget: {}, target: {}, @@ -321,4 +321,21 @@ describe('type()', () => { const eventNames = events.map((event) => event.name); expect(eventNames).toEqual(['focus', 'changeText', 'changeText', 'changeText', 'blur']); }); + + // See: https://github.com/callstack/react-native-testing-library/issues/1588 + it('can call "persist()" on "onKeyPress" event handler', async () => { + const handleKeyPress = jest.fn(); + render( + { + e.persist(); + handleKeyPress(); + }} + />, + ); + + await userEvent.type(screen.getByTestId('input'), 'abc'); + expect(handleKeyPress).toHaveBeenCalledTimes(3); + }); });