diff --git a/src/user-event/type/__tests__/type-managed.test.tsx b/src/user-event/type/__tests__/type-managed.test.tsx index 37e9f03c..6b1f45c9 100644 --- a/src/user-event/type/__tests__/type-managed.test.tsx +++ b/src/user-event/type/__tests__/type-managed.test.tsx @@ -110,4 +110,31 @@ describe('type() for managed TextInput', () => { expect(events).toMatchSnapshot('input: "ABC", value: "XXX"'); }); + + it('skips blur and endEditing events when `skipBlur: true` in managed TextInput', async () => { + const { events, logEvent } = createEventLogger(); + render(); + + const user = userEvent.setup(); + await user.type(screen.getByTestId('input'), 'a', { + skipBlur: true, + }); + + const eventNames = getEventsNames(events); + + // Ensure 'endEditing' and 'blur' are not present + expect(eventNames).not.toContain('endEditing'); + expect(eventNames).not.toContain('blur'); + + // Verify the exact events that should be present + expect(eventNames).toEqual([ + 'pressIn', + 'focus', + 'pressOut', + 'keyPress', + 'change', + 'changeText', + 'selectionChange', + ]); + }); }); diff --git a/src/user-event/type/__tests__/type.test.tsx b/src/user-event/type/__tests__/type.test.tsx index 5753f416..474216f5 100644 --- a/src/user-event/type/__tests__/type.test.tsx +++ b/src/user-event/type/__tests__/type.test.tsx @@ -386,4 +386,34 @@ describe('type()', () => { await user.type(input, ' World'); expect(input).toHaveDisplayValue('Hello World'); }); + + it('skips blur and endEditing events when `skipBlur: true`', async () => { + const { events } = renderTextInputWithToolkit(); + + const user = userEvent.setup(); + await user.type(screen.getByTestId('input'), 'a', { + skipBlur: true, + }); + + const eventNames = getEventsNames(events); + + // Ensure 'endEditing' and 'blur' are not present + expect(eventNames).not.toContain('endEditing'); + expect(eventNames).not.toContain('blur'); + + // Verify the exact events that should be present + expect(eventNames).toEqual([ + 'pressIn', + 'focus', + 'pressOut', + 'keyPress', + 'change', + 'changeText', + 'selectionChange', + ]); + + expect(lastEventPayload(events, 'selectionChange')).toMatchObject({ + nativeEvent: { selection: { start: 1, end: 1 } }, + }); + }); });