Skip to content

Commit

Permalink
test: 添加测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
xliez committed Dec 26, 2023
1 parent d149739 commit 929001f
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/Select.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { LabelInValueType } from '@/Select';
import { fireEvent, render as testingRender } from '@testing-library/react';
import { mount, render } from 'enzyme';
import KeyCode from 'rc-util/lib/KeyCode';
Expand All @@ -23,7 +24,6 @@ import {
selectItem,
toggleOpen,
} from './utils/common';
import { LabelInValueType } from '@/Select';

describe('Select.Basic', () => {
injectRunAllTimers(jest);
Expand Down Expand Up @@ -2150,4 +2150,36 @@ describe('Select.Basic', () => {
expect(onLabelRender).toHaveBeenCalled();
expect(findSelection(wrapper).text()).toEqual('fakeLabel-a');
});

it('labelRender when labelInValue and useCache', () => {
const onLabelRender = jest.fn();
const labelRender = (props: LabelInValueType) => {
const { label, value } = props;
console.log('[ label ]-2158', label);
onLabelRender({ label, value });
return `custom label`;
};

const wrapper = mount(
<Select
labelInValue
value={{ key: 1, label: 'One' }}
labelRender={labelRender}
options={[
{
value: 2,
label: 'Two',
},
]}
/>,
);

expect(onLabelRender).toHaveBeenCalledWith({ label: 'One', value: 1 });
expect(findSelection(wrapper).text()).toEqual('custom label');

wrapper.setProps({ options: [] });

expect(findSelection(wrapper).text()).toEqual('custom label');

});
});

0 comments on commit 929001f

Please sign in to comment.