From baaccd574e9a181cbcbe80bc56a2003215daa331 Mon Sep 17 00:00:00 2001 From: zkwolf Date: Wed, 18 Aug 2021 15:41:21 +0800 Subject: [PATCH] fix(switch): custom checkedChildren unexpected (#4528) * fix(switch): custom checkedChildren unexpected * Update index.tsx Co-authored-by: tangjinzhou <415800467@qq.com> --- components/switch/__tests__/index.test.js | 31 +++++++++++++++++++++++ components/switch/index.tsx | 3 ++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/components/switch/__tests__/index.test.js b/components/switch/__tests__/index.test.js index 5fb8e501c..5770a9934 100644 --- a/components/switch/__tests__/index.test.js +++ b/components/switch/__tests__/index.test.js @@ -70,4 +70,35 @@ describe('Switch', () => { }); expect(checked.value).toBe(1); }); + + it('customize checked value and children should work', async () => { + resetWarned(); + const checked = ref(1); + const onUpdate = val => (checked.value = val); + const wrapper = mount({ + render() { + return ( + + ); + }, + }); + await asyncExpect(() => { + wrapper.find('button').trigger('click'); + }); + expect(checked.value).toBe(2); + expect(wrapper.find('.ant-switch-inner').text()).toBe('on'); + + await asyncExpect(() => { + wrapper.find('button').trigger('click'); + }); + expect(checked.value).toBe(1); + expect(wrapper.find('.ant-switch-inner').text()).toBe('off'); + }); }); diff --git a/components/switch/index.tsx b/components/switch/index.tsx index 0d038946a..719ef670e 100644 --- a/components/switch/index.tsx +++ b/components/switch/index.tsx @@ -134,6 +134,7 @@ const Switch = defineComponent({ [`${prefixCls.value}-disabled`]: props.disabled, [prefixCls.value]: true, })); + return () => (