Skip to content

Commit 8c88ca5

Browse files
author
Dipak Sarkar
committed
updated test unit
1 parent d710e91 commit 8c88ca5

File tree

1 file changed

+53
-55
lines changed

1 file changed

+53
-55
lines changed

tests/unit/number-format.custom.spec.js

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ describe('when the value is invalid with custom config', () => {
2424
expect(numberFormat.format('!@#$%^&*()')).toEqual('')
2525
})
2626
it('should return as follows', () => {
27-
expect(numberFormat.clean().format('')).toEqual('')
28-
expect(numberFormat.clean().format('foo')).toEqual('')
29-
expect(numberFormat.clean().format('-foo')).toEqual('')
30-
expect(numberFormat.clean().format('-fo.o-')).toEqual('')
31-
expect(numberFormat.clean().format('-fo,o-')).toEqual('')
32-
expect(numberFormat.clean().format('!@#$%^&*()')).toEqual('')
27+
expect(numberFormat.clean(true).format('')).toEqual('')
28+
expect(numberFormat.clean(true).format('foo')).toEqual('')
29+
expect(numberFormat.clean(true).format('-foo')).toEqual('')
30+
expect(numberFormat.clean(true).format('-fo.o-')).toEqual('')
31+
expect(numberFormat.clean(true).format('-fo,o-')).toEqual('')
32+
expect(numberFormat.clean(true).format('!@#$%^&*()')).toEqual('')
3333
})
3434
it('should return as follows', () => {
35-
expect(numberFormat.unformat('')).toEqual('')
36-
expect(numberFormat.unformat('foo')).toEqual('')
37-
expect(numberFormat.unformat('-foo')).toEqual('')
38-
expect(numberFormat.unformat('-fo.o-')).toEqual('')
39-
expect(numberFormat.unformat('!@#$%^&*()')).toEqual('')
35+
expect(numberFormat.clean(true).unformat('')).toEqual('')
36+
expect(numberFormat.clean(true).unformat('foo')).toEqual('')
37+
expect(numberFormat.clean(true).unformat('-foo')).toEqual('')
38+
expect(numberFormat.clean(true).unformat('-fo.o-')).toEqual('')
39+
expect(numberFormat.clean(true).unformat('!@#$%^&*()')).toEqual('')
4040
})
4141
})
4242
describe('format when options are custom', () => {
@@ -53,34 +53,34 @@ describe('format when options are custom', () => {
5353
expect(numberFormat.format('0,10')).toEqual('$0,10')
5454
expect(numberFormat.format('0,0-')).toEqual('$0,0')
5555
expect(numberFormat.format('0,10-')).toEqual('-$0,10')
56-
expect(numberFormat.format('12.345,54921')).toEqual('$12.345,55')
57-
expect(numberFormat.format('--12.345,12345')).toEqual('-$12.345,12')
58-
expect(numberFormat.format('12.345.54321,12945')).toEqual('$1.234.554.321,13')
59-
expect(numberFormat.format('-12.345,,54321-')).toEqual('-$12.345,54')
56+
expect(numberFormat.format('12.345,54921')).toEqual('$12.345,54921')
57+
expect(numberFormat.format('--12.345,12345')).toEqual('-$12.345,12345')
58+
expect(numberFormat.format('12.345.54321,12945')).toEqual('$1.234.554.321,12945')
59+
expect(numberFormat.format('-12.345,,54321-')).toEqual('-$12.345,54321')
6060
})
6161
it('format numerical value', () => {
62-
expect(numberFormat.format(0)).toEqual('$0')
63-
expect(numberFormat.format(0.)).toEqual('$0')
64-
expect(numberFormat.format(0.0)).toEqual('$0')
62+
expect(numberFormat.format(0)).toEqual('')
63+
expect(numberFormat.format(0.)).toEqual('')
64+
expect(numberFormat.format(0.0)).toEqual('')
6565
expect(numberFormat.format(-0.10)).toEqual('-$0,1')
66-
expect(numberFormat.format(-0.0)).toEqual('$0')
66+
expect(numberFormat.format(-0.0)).toEqual('')
6767
expect(numberFormat.format(0.10)).toEqual('$0,1')
68-
expect(numberFormat.format(12345.54921)).toEqual('$12.345,55')
69-
expect(numberFormat.format(12345.12345)).toEqual('$12.345,12')
70-
expect(numberFormat.format(12345.54321)).toEqual('$12.345,54')
71-
expect(numberFormat.format(12345.54321)).toEqual('$12.345,54')
68+
expect(numberFormat.format(12345.54921)).toEqual('$12.345,54921')
69+
expect(numberFormat.format(12345.12345)).toEqual('$12.345,12345')
70+
expect(numberFormat.format(12345.54321)).toEqual('$12.345,54321')
71+
expect(numberFormat.format(12345.54321)).toEqual('$12.345,54321')
7272
})
7373
it('format and clean numerical value', () => {
74-
expect(numberFormat.clean().format(0)).toEqual('$0')
75-
expect(numberFormat.clean().format(0.)).toEqual('$0')
76-
expect(numberFormat.clean().format(0.0)).toEqual('$0')
77-
expect(numberFormat.clean().format(0.10)).toEqual('$0,1')
78-
expect(numberFormat.clean().format(-0.0)).toEqual('$0')
79-
expect(numberFormat.clean().format(-0.10)).toEqual('-$0,1')
80-
expect(numberFormat.clean().format(12345.54921)).toEqual('$12.345,55')
81-
expect(numberFormat.clean().format(12345.12345)).toEqual('$12.345,12')
82-
expect(numberFormat.clean().format(12345.54321)).toEqual('$12.345,54')
83-
expect(numberFormat.clean().format(12345.54321)).toEqual('$12.345,54')
74+
expect(numberFormat.clean(true).format(0)).toEqual('')
75+
expect(numberFormat.clean(true).format(0.)).toEqual('')
76+
expect(numberFormat.clean(true).format(0.0)).toEqual('')
77+
expect(numberFormat.clean(true).format(0.10)).toEqual('$0,1')
78+
expect(numberFormat.clean(true).format(-0.0)).toEqual('')
79+
expect(numberFormat.clean(true).format(-0.10)).toEqual('-$0,1')
80+
expect(numberFormat.clean(true).format(12345.54921)).toEqual('$12.345,55')
81+
expect(numberFormat.clean(true).format(12345.12345)).toEqual('$12.345,12')
82+
expect(numberFormat.clean(true).format(12345.54321)).toEqual('$12.345,54')
83+
expect(numberFormat.clean(true).format(12345.54321)).toEqual('$12.345,54')
8484
})
8585
})
8686
describe('unformat when options are default', () => {
@@ -91,29 +91,27 @@ describe('unformat when options are default', () => {
9191
null_value: '',
9292
})
9393
it('unformat string value', () => {
94-
expect(numberFormat.unformat('0')).toEqual(0)
95-
expect(numberFormat.unformat('0,')).toEqual(0)
96-
expect(numberFormat.unformat('-0,0')).toEqual(0)
97-
expect(numberFormat.unformat('0,10')).toEqual(0.1)
98-
expect(numberFormat.unformat('0,0-')).toEqual(0)
99-
expect(numberFormat.unformat('0,10-')).toEqual(-0.1)
100-
expect(numberFormat.unformat('12.345,54921')).toEqual(12345.55)
101-
expect(numberFormat.unformat('--12.345,12345')).toEqual(-12345.12)
102-
expect(numberFormat.unformat('12.345.54321,12345')).toEqual(1234554321.12)
103-
expect(numberFormat.unformat('-12.345,,54321-')).toEqual(-12345.54)
94+
expect(numberFormat.clean(true).unformat('0')).toEqual(0)
95+
expect(numberFormat.clean(true).unformat('0,')).toEqual(0)
96+
expect(numberFormat.clean(true).unformat('-0,0')).toEqual(0)
97+
expect(numberFormat.clean(true).unformat('0,10')).toEqual(0.1)
98+
expect(numberFormat.clean(true).unformat('0,0-')).toEqual(0)
99+
expect(numberFormat.clean(true).unformat('0,10-')).toEqual(-0.1)
100+
expect(numberFormat.clean(true).unformat('12.345,54921')).toEqual(12345.55)
101+
expect(numberFormat.clean(true).unformat('--12.345,12345')).toEqual(-12345.12)
102+
expect(numberFormat.clean(true).unformat('12.345.54321,12345')).toEqual(1234554321.12)
103+
expect(numberFormat.clean(true).unformat('-12.345,,54321-')).toEqual(-12345.54)
104104
})
105105
it('unformat numerical value', () => {
106-
expect(numberFormat.unformat(0)).toEqual(0)
107-
expect(numberFormat.unformat(0.)).toEqual(0)
108-
expect(numberFormat.unformat(0.0)).toEqual(0)
109-
expect(numberFormat.unformat(-0.10)).toEqual(-0.1)
110-
expect(numberFormat.unformat(-0.0)).toEqual(0)
111-
expect(numberFormat.unformat(0.10)).toEqual(0.1)
112-
expect(numberFormat.unformat(12345.54921)).toEqual(12345.55)
113-
expect(numberFormat.unformat(12345.12345)).toEqual(12345.12)
114-
expect(numberFormat.unformat(12345.54321)).toEqual(12345.54)
115-
expect(numberFormat.unformat(12345.54321)).toEqual(12345.54)
106+
expect(numberFormat.clean(true).unformat(0)).toEqual('')
107+
expect(numberFormat.clean(true).unformat(0.)).toEqual('')
108+
expect(numberFormat.clean(true).unformat(0.0)).toEqual('')
109+
expect(numberFormat.clean(true).unformat(-0.10)).toEqual(-0.1)
110+
expect(numberFormat.clean(true).unformat(-0.0)).toEqual('')
111+
expect(numberFormat.clean(true).unformat(0.10)).toEqual(0.1)
112+
expect(numberFormat.clean(true).unformat(12345.54921)).toEqual(12345.55)
113+
expect(numberFormat.clean(true).unformat(12345.12345)).toEqual(12345.12)
114+
expect(numberFormat.clean(true).unformat(12345.54321)).toEqual(12345.54)
115+
expect(numberFormat.clean(true).unformat(12345.54321)).toEqual(12345.54)
116116
})
117117
})
118-
119-

0 commit comments

Comments
 (0)