MCPcopy Create free account
hub / github.com/react-component/select / removeSelectedTest

Function removeSelectedTest

tests/shared/removeSelectedTest.tsx:7–104  ·  view source on GitHub ↗
(mode: any)

Source from the content-addressed store, hash-verified

5import { render } from '@testing-library/react';
6
7export default function removeSelectedTest(mode: any) {
8 describe('remove selected options', () => {
9 it('fires deselect and change', () => {
10 const handleDeselect = jest.fn();
11 const handleChange = jest.fn();
12 const { container } = render(
13 <Select value={['1', '2']} onChange={handleChange} onDeselect={handleDeselect} mode={mode}>
14 <Option value="1" testprop="deselect">
15 1
16 </Option>
17 <Option value="2">2</Option>
18 </Select>,
19 );
20 removeSelection(container);
21
22 expect(handleDeselect).toBeCalledWith(
23 '1',
24 expect.objectContaining({ value: '1', testprop: 'deselect' }),
25 );
26 expect(handleChange).toBeCalledWith(['2'], expect.anything());
27 });
28
29 it('noop if select is disabled', () => {
30 const handleDeselect = jest.fn();
31 const handleChange = jest.fn();
32 const { container } = render(
33 <Select
34 value={['1']}
35 onChange={handleChange}
36 onDeselect={handleDeselect}
37 disabled
38 mode={mode}
39 >
40 <Option value="1">1</Option>
41 <Option value="2">2</Option>
42 </Select>,
43 );
44
45 expect(container.querySelector('.rc-select-selection-item-remove')).toBeFalsy();
46 });
47
48 it('wrap value when labelInValue', () => {
49 const handleDeselect = jest.fn();
50 const handleChange = jest.fn();
51 const { container } = render(
52 <Select
53 value={[{ key: '1' }, { key: '2' }]}
54 onChange={handleChange}
55 onDeselect={handleDeselect}
56 labelInValue
57 mode={mode}
58 >
59 <Option value="1">1</Option>
60 <Option value="2">2</Option>
61 </Select>,
62 );
63 removeSelection(container);
64

Callers 2

Tags.test.tsxFile · 0.85
Multiple.test.tsxFile · 0.85

Calls 4

removeSelectionFunction · 0.90
keyDownFunction · 0.90
toggleOpenFunction · 0.90
selectItemFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…