From 927cfb5c85deaaaaa9cc8af3fe5d30e9a5f2c1ab Mon Sep 17 00:00:00 2001 From: zombiej Date: Tue, 15 Feb 2022 16:51:55 +0800 Subject: [PATCH] fix: no need warning when provide optionLabelProp --- src/Select.tsx | 2 +- tests/Multiple.test.tsx | 78 ++++++++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/Select.tsx b/src/Select.tsx index 8ac3c8937..99e72bfe9 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -253,7 +253,7 @@ const Select = React.forwardRef( rawDisabled = option?.disabled; // Warning if label not same as provided - if (process.env.NODE_ENV !== 'production' && !isRawValue(val)) { + if (process.env.NODE_ENV !== 'production' && !optionLabelProp) { const optionLabel = option?.[mergedFieldNames.label]; if (optionLabel !== undefined && optionLabel !== rawLabel) { warning(false, '`label` of `value` is not same as `label` in Select options.'); diff --git a/tests/Multiple.test.tsx b/tests/Multiple.test.tsx index 6067287c1..a5e6f6b6e 100644 --- a/tests/Multiple.test.tsx +++ b/tests/Multiple.test.tsx @@ -475,31 +475,59 @@ describe('Select.Multiple', () => { expect(wrapper.exists('.rc-select-selection-item-remove')).toBeFalsy(); }); - it('optionLabelProp', () => { - const wrapper = mount( - , + ); - expect(findSelection(wrapper, 0).text()).toBe('BAMBOO'); - expect(findSelection(wrapper, 1).text()).toBe('LITTLE'); - expect(wrapper.find('div.rc-select-item-option-content').at(0).text()).toBe('Bamboo'); - expect(wrapper.find('div.rc-select-item-option-content').at(1).text()).toBe('Little'); + expect(findSelection(wrapper, 0).text()).toBe('BAMBOO'); + expect(findSelection(wrapper, 1).text()).toBe('LITTLE'); + expect(wrapper.find('div.rc-select-item-option-content').at(0).text()).toBe('Bamboo'); + expect(wrapper.find('div.rc-select-item-option-content').at(1).text()).toBe('Little'); + }); + + it('select no warning', () => { + const wrapper = mount( +