Skip to content

Commit ecb1014

Browse files
mrpmohiburrahmanmdjastrzebski
authored andcommitted
test: add unit testing for skipBlur
1 parent c8ab9f9 commit ecb1014

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/user-event/type/__tests__/type-managed.test.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,31 @@ describe('type() for managed TextInput', () => {
110110

111111
expect(events).toMatchSnapshot('input: "ABC", value: "XXX"');
112112
});
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+
});
113140
});

src/user-event/type/__tests__/type.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,34 @@ describe('type()', () => {
386386
await user.type(input, ' World');
387387
expect(input).toHaveDisplayValue('Hello World');
388388
});
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+
});
389419
});

0 commit comments

Comments
 (0)