@@ -60,6 +60,48 @@ describe('Helpers Unit Tests', () => {
6060 expect ( num , 'to match' , / 1 [ , . ] 0 { 3 } [ , . ] 0 { 3 } [ , . ] 0 { 2 } / ) ;
6161 expect ( num , 'to match' , / \$ { 1 } / ) ;
6262 } ) ;
63+
64+ it ( 'should display one cent' , ( ) => {
65+ const num = helpers . formatFiat ( 0.01 , 'usd' ) ;
66+ expect ( num , 'to match' , / 0 [ , . ] 0 { 1 } 1 { 1 } / ) ;
67+ expect ( num , 'to match' , / \$ { 1 } / ) ;
68+ expect ( num , 'not to match' , / ^ < / ) ;
69+ } ) ;
70+
71+ it ( 'should round up to one cent' , ( ) => {
72+ const num = helpers . formatFiat ( 0.005 , 'usd' ) ;
73+ expect ( num , 'to match' , / 0 [ , . ] 0 { 1 } 1 { 1 } / ) ;
74+ expect ( num , 'to match' , / \$ { 1 } / ) ;
75+ expect ( num , 'not to match' , / ^ < / ) ;
76+ } ) ;
77+
78+ it ( 'should display less than a cent' , ( ) => {
79+ const num = helpers . formatFiat ( 0.004 , 'usd' ) ;
80+ expect ( num , 'to match' , / 0 [ , . ] 0 { 1 } 1 { 1 } / ) ;
81+ expect ( num , 'to match' , / \$ { 1 } / ) ;
82+ expect ( num , 'to match' , / ^ < / ) ;
83+ } ) ;
84+
85+ it ( 'should display less than a cent for small numbers' , ( ) => {
86+ const num = helpers . formatFiat ( 0.0000001 , 'usd' ) ;
87+ expect ( num , 'to match' , / 0 [ , . ] 0 { 1 } 1 { 1 } / ) ;
88+ expect ( num , 'to match' , / \$ { 1 } / ) ;
89+ expect ( num , 'to match' , / ^ < / ) ;
90+ } ) ;
91+
92+ it ( 'should display less than a cent for negative small numbers' , ( ) => {
93+ const num = helpers . formatFiat ( 0.999999 - 1 , 'usd' ) ;
94+ expect ( num , 'to match' , / 0 [ , . ] 0 { 1 } 1 { 1 } / ) ;
95+ expect ( num , 'to match' , / \$ { 1 } / ) ;
96+ expect ( num , 'to match' , / ^ < - / ) ;
97+ } ) ;
98+
99+ it ( 'should display 0.00 without less than' , ( ) => {
100+ const num = helpers . formatFiat ( 0.0 , 'usd' ) ;
101+ expect ( num , 'to match' , / 0 [ , . ] 0 { 2 } / ) ;
102+ expect ( num , 'to match' , / \$ { 1 } / ) ;
103+ expect ( num , 'not to match' , / ^ < / ) ;
104+ } ) ;
63105 } ) ;
64106
65107 describe ( 'parseDate()' , ( ) => {
0 commit comments