From d0914f34ade81e1d55b858df1f8a6ddad9a2ccdb Mon Sep 17 00:00:00 2001 From: Tmk <i@tmk.im> Date: Sun, 22 Aug 2021 19:39:26 +0800 Subject: [PATCH] fix(Rate): convert count type (#9307) * fix(rate): convert count type * test(Rate): add count string prop case --- src/rate/Rate.tsx | 2 +- src/rate/test/index.spec.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/rate/Rate.tsx b/src/rate/Rate.tsx index 13b848696..1ac0d5295 100644 --- a/src/rate/Rate.tsx +++ b/src/rate/Rate.tsx @@ -87,7 +87,7 @@ export default defineComponent({ props.readonly || props.disabled || !props.touchable; const list = computed<RateListItem[]>(() => - Array(props.count) + Array(+props.count) .fill('') .map((_, i) => getRateStatus( diff --git a/src/rate/test/index.spec.ts b/src/rate/test/index.spec.ts index b0dde45b6..a1ecabc08 100644 --- a/src/rate/test/index.spec.ts +++ b/src/rate/test/index.spec.ts @@ -127,3 +127,15 @@ test('should get decimal when using allow-half and readonly prop', () => { const halfIcon = wrapper.find('.van-rate__icon--half'); expect(halfIcon.style.width).toEqual('0.3em'); }); + +test('should render correct count when using string prop', () => { + const wrapper = mount(Rate, { + props: { + count: '4', + }, + }); + + const icons = wrapper.findAll('.van-rate__item'); + + expect(icons).toHaveLength(4); +});