File tree 2 files changed +57
-0
lines changed
src/user-event/type/__tests__
2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -110,4 +110,31 @@ describe('type() for managed TextInput', () => {
110
110
111
111
expect ( events ) . toMatchSnapshot ( 'input: "ABC", value: "XXX"' ) ;
112
112
} ) ;
113
+
114
+ it ( 'skips blur and endEditing events when `skipBlur: true` in managed TextInput' , async ( ) => {
115
+ const { events, logEvent } = createEventLogger ( ) ;
116
+ render ( < ManagedTextInput logEvent = { logEvent } /> ) ;
117
+
118
+ const user = userEvent . setup ( ) ;
119
+ await user . type ( screen . getByTestId ( 'input' ) , 'a' , {
120
+ skipBlur : true ,
121
+ } ) ;
122
+
123
+ const eventNames = getEventsNames ( events ) ;
124
+
125
+ // Ensure 'endEditing' and 'blur' are not present
126
+ expect ( eventNames ) . not . toContain ( 'endEditing' ) ;
127
+ expect ( eventNames ) . not . toContain ( 'blur' ) ;
128
+
129
+ // Verify the exact events that should be present
130
+ expect ( eventNames ) . toEqual ( [
131
+ 'pressIn' ,
132
+ 'focus' ,
133
+ 'pressOut' ,
134
+ 'keyPress' ,
135
+ 'change' ,
136
+ 'changeText' ,
137
+ 'selectionChange' ,
138
+ ] ) ;
139
+ } ) ;
113
140
} ) ;
Original file line number Diff line number Diff line change @@ -386,4 +386,34 @@ describe('type()', () => {
386
386
await user . type ( input , ' World' ) ;
387
387
expect ( input ) . toHaveDisplayValue ( 'Hello World' ) ;
388
388
} ) ;
389
+
390
+ it ( 'skips blur and endEditing events when `skipBlur: true`' , async ( ) => {
391
+ const { events } = renderTextInputWithToolkit ( ) ;
392
+
393
+ const user = userEvent . setup ( ) ;
394
+ await user . type ( screen . getByTestId ( 'input' ) , 'a' , {
395
+ skipBlur : true ,
396
+ } ) ;
397
+
398
+ const eventNames = getEventsNames ( events ) ;
399
+
400
+ // Ensure 'endEditing' and 'blur' are not present
401
+ expect ( eventNames ) . not . toContain ( 'endEditing' ) ;
402
+ expect ( eventNames ) . not . toContain ( 'blur' ) ;
403
+
404
+ // Verify the exact events that should be present
405
+ expect ( eventNames ) . toEqual ( [
406
+ 'pressIn' ,
407
+ 'focus' ,
408
+ 'pressOut' ,
409
+ 'keyPress' ,
410
+ 'change' ,
411
+ 'changeText' ,
412
+ 'selectionChange' ,
413
+ ] ) ;
414
+
415
+ expect ( lastEventPayload ( events , 'selectionChange' ) ) . toMatchObject ( {
416
+ nativeEvent : { selection : { start : 1 , end : 1 } } ,
417
+ } ) ;
418
+ } ) ;
389
419
} ) ;
You can’t perform that action at this time.
0 commit comments