|
1 | 1 | import { mount } from 'enzyme';
|
2 | 2 | import KeyCode from 'rc-util/lib/KeyCode';
|
3 | 3 | import React from 'react';
|
4 |
| -import { resetWarned } from 'rc-util/lib/warning'; |
5 | 4 | import Select, { Option, OptGroup } from '../src';
|
6 | 5 | import focusTest from './shared/focusTest';
|
7 | 6 | import blurTest from './shared/blurTest';
|
@@ -129,7 +128,10 @@ describe('Select.Multiple', () => {
|
129 | 128 |
|
130 | 129 | expect(handleChange).toHaveBeenCalledWith(
|
131 | 130 | [1, 2],
|
132 |
| - [expect.objectContaining({ value: 1 }), expect.objectContaining({ value: 2, testprop: 2 })], |
| 131 | + [ |
| 132 | + expect.objectContaining({ value: 1 }), |
| 133 | + expect.objectContaining({ value: 2, testprop: 2 }), |
| 134 | + ], |
133 | 135 | );
|
134 | 136 | });
|
135 | 137 |
|
@@ -239,4 +241,37 @@ describe('Select.Multiple', () => {
|
239 | 241 | });
|
240 | 242 | expect(wrapper.find('.rc-select-arrow-icon').length).toBeTruthy();
|
241 | 243 | });
|
| 244 | + |
| 245 | + it('block input when fast backspace', () => { |
| 246 | + jest.useFakeTimers(); |
| 247 | + const onChange = jest.fn(); |
| 248 | + |
| 249 | + const wrapper = mount( |
| 250 | + <Select |
| 251 | + mode="multiple" |
| 252 | + value={['bamboo']} |
| 253 | + options={[{ value: 'bamboo' }, { value: 'light' }]} |
| 254 | + onChange={onChange} |
| 255 | + />, |
| 256 | + ); |
| 257 | + |
| 258 | + // First type |
| 259 | + wrapper.find('input').simulate('keydown', { which: KeyCode.L }); |
| 260 | + wrapper.find('input').simulate('change', { target: { value: 'l' } }); |
| 261 | + |
| 262 | + // Backspace |
| 263 | + wrapper.find('input').simulate('keydown', { which: KeyCode.BACKSPACE }); |
| 264 | + wrapper.find('input').simulate('change', { target: { value: '' } }); |
| 265 | + |
| 266 | + onChange.mockReset(); |
| 267 | + |
| 268 | + wrapper.find('input').simulate('keydown', { which: KeyCode.BACKSPACE }); |
| 269 | + expect(onChange).not.toHaveBeenCalled(); |
| 270 | + |
| 271 | + jest.runAllTimers(); |
| 272 | + wrapper.find('input').simulate('keydown', { which: KeyCode.BACKSPACE }); |
| 273 | + expect(onChange).toHaveBeenCalledWith([], expect.anything()); |
| 274 | + |
| 275 | + jest.useRealTimers(); |
| 276 | + }); |
242 | 277 | });
|
0 commit comments