From 172ed6eaeee6987418b510bb29dd38cd5f0b44b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Fri, 7 Jun 2019 10:52:19 +0800 Subject: [PATCH] [bugfix] Switch: incorrect activeColor when use activeValue --- packages/switch/index.tsx | 4 ++-- .../switch/test/__snapshots__/index.spec.js.snap | 7 +++++++ packages/switch/test/index.spec.js | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 packages/switch/test/__snapshots__/index.spec.js.snap diff --git a/packages/switch/index.tsx b/packages/switch/index.tsx index e8e5dcef2..900b9ecc1 100644 --- a/packages/switch/index.tsx +++ b/packages/switch/index.tsx @@ -35,10 +35,10 @@ function Switch( const switchStyle = { fontSize: size, - backgroundColor: value ? activeColor : inactiveColor + backgroundColor: checked ? activeColor : inactiveColor }; - const loadingColor = value ? activeColor || BLUE : inactiveColor || GRAY_DARK; + const loadingColor = checked ? activeColor || BLUE : inactiveColor || GRAY_DARK; function onClick() { if (!disabled && !loading) { diff --git a/packages/switch/test/__snapshots__/index.spec.js.snap b/packages/switch/test/__snapshots__/index.spec.js.snap new file mode 100644 index 000000000..d2a276311 --- /dev/null +++ b/packages/switch/test/__snapshots__/index.spec.js.snap @@ -0,0 +1,7 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`inactive-color prop 1`] = ` +
+
+
+`; diff --git a/packages/switch/test/index.spec.js b/packages/switch/test/index.spec.js index d822b68f4..bbc2987d2 100644 --- a/packages/switch/test/index.spec.js +++ b/packages/switch/test/index.spec.js @@ -60,3 +60,15 @@ test('active-value & inactive-value prop', () => { expect(input).toHaveBeenCalledWith('2'); expect(change).toHaveBeenCalledWith('2'); }); + +test('inactive-color prop', () => { + const wrapper = mount(Switch, { + propsData: { + value: '2', + inactiveValue: '2', + inactiveColor: 'black' + } + }); + + expect(wrapper).toMatchSnapshot(); +});