From 4d1e1b587171c48627e9c2e7bf71e2dd885d4046 Mon Sep 17 00:00:00 2001 From: inottn Date: Wed, 5 Jun 2024 22:28:05 +0800 Subject: [PATCH] fix(Card): render correctly when the price is an integer (#12917) --- packages/vant/src/card/Card.tsx | 8 ++++++-- .../src/card/test/__snapshots__/demo-ssr.spec.ts.snap | 3 +++ packages/vant/src/card/test/index.spec.ts | 10 ++++++++++ .../test/__snapshots__/demo-ssr.spec.ts.snap | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/vant/src/card/Card.tsx b/packages/vant/src/card/Card.tsx index 79d4c92e1..086045c77 100644 --- a/packages/vant/src/card/Card.tsx +++ b/packages/vant/src/card/Card.tsx @@ -108,8 +108,12 @@ export default defineComponent({ return (
{props.currency} - {priceArr[0]}. - {priceArr[1]} + {priceArr[0]} + {priceArr.length > 1 && ( + <> + .{priceArr[1]} + + )}
); }; diff --git a/packages/vant/src/card/test/__snapshots__/demo-ssr.spec.ts.snap b/packages/vant/src/card/test/__snapshots__/demo-ssr.spec.ts.snap index 26544a7a5..25a7d8511 100644 --- a/packages/vant/src/card/test/__snapshots__/demo-ssr.spec.ts.snap +++ b/packages/vant/src/card/test/__snapshots__/demo-ssr.spec.ts.snap @@ -44,6 +44,7 @@ exports[`should render demo and match snapshot 1`] = ` 2 + . 00 @@ -109,6 +110,7 @@ exports[`should render demo and match snapshot 1`] = ` 2 + . 00 @@ -183,6 +185,7 @@ exports[`should render demo and match snapshot 1`] = ` 2 + . 00 diff --git a/packages/vant/src/card/test/index.spec.ts b/packages/vant/src/card/test/index.spec.ts index 059dcd38c..dfe0808db 100644 --- a/packages/vant/src/card/test/index.spec.ts +++ b/packages/vant/src/card/test/index.spec.ts @@ -86,3 +86,13 @@ test('should render price and price-top slot correctly', () => { expect(wrapper.html()).toMatchSnapshot(); }); + +test('should render correctly when the price is an integer', () => { + const wrapper = mount(Card, { + props: { + price: 12, + }, + }); + + expect(wrapper.find('.van-card__price').text()).toEqual('¥12'); +}); diff --git a/packages/vant/src/swipe-cell/test/__snapshots__/demo-ssr.spec.ts.snap b/packages/vant/src/swipe-cell/test/__snapshots__/demo-ssr.spec.ts.snap index 498f590bd..76b6ca6b5 100644 --- a/packages/vant/src/swipe-cell/test/__snapshots__/demo-ssr.spec.ts.snap +++ b/packages/vant/src/swipe-cell/test/__snapshots__/demo-ssr.spec.ts.snap @@ -115,6 +115,7 @@ exports[`should render demo and match snapshot 1`] = ` 2 + . 00