File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -4,4 +4,4 @@ type priceProp = {
44} ;
55
66export const parsePrice = ( { price } : priceProp ) =>
7- price . replace ( / \. 0 * / , '' ) . replace ( / , / g, ' ' ) ;
7+ price . replace ( / \. 0 + / , '' ) . replace ( / , / g, ' ' ) ;
Original file line number Diff line number Diff line change 11import { parsePrice } from './price' ;
22
3- it ( 'remove penny ' , ( ) => {
3+ it ( 'removes zero pennies ' , ( ) => {
44 expect ( parsePrice ( { price : '42.00 Kč' } ) ) . toEqual ( '42 Kč' ) ;
55 expect ( parsePrice ( { price : '1.00 Kč' } ) ) . toEqual ( '1 Kč' ) ;
66 expect ( parsePrice ( { price : '1.0000' } ) ) . toEqual ( '1' ) ;
77 expect ( parsePrice ( { price : '1.0' } ) ) . toEqual ( '1' ) ;
88} ) ;
99
10+ it ( 'keep non-zero pennies' , ( ) => {
11+ expect ( parsePrice ( { price : '42.80 Kč' } ) ) . toEqual ( '42.80 Kč' ) ;
12+ expect ( parsePrice ( { price : '1.8 Kč' } ) ) . toEqual ( '1.8 Kč' ) ;
13+ expect ( parsePrice ( { price : '1.42' } ) ) . toEqual ( '1.42' ) ;
14+ expect ( parsePrice ( { price : '1.4' } ) ) . toEqual ( '1.4' ) ;
15+ } ) ;
16+
1017it ( 'replace comma with space' , ( ) => {
1118 expect ( parsePrice ( { price : '42,000,243,000 Kč' } ) ) . toEqual (
1219 '42 000 243 000 Kč' ,
1320 ) ;
1421} ) ;
1522
16- it ( 'remove penny and replace comma with space' , ( ) => {
23+ it ( 'remove pennies and replace commas with space' , ( ) => {
1724 expect ( parsePrice ( { price : '42,123.00 Kč' } ) ) . toEqual ( '42 123 Kč' ) ;
1825} ) ;
You can’t perform that action at this time.
0 commit comments