-
Notifications
You must be signed in to change notification settings - Fork 7
/
finance.test.js
64 lines (57 loc) · 2.29 KB
/
finance.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var should = require('should'),
BrM = require('../releases/br-masks');
describe('FINANCE', function(){
it('should maks 125 to 125.00', function(done) {
should(BrM.finance('125')).be.eql('125.00');
should(BrM.finance(125)).be.eql('125.00');
done();
});
it('should maks -125 to (125.00)', function(done) {
should(BrM.finance('-125')).be.eql('(125.00)');
should(BrM.finance(-125)).be.eql('(125.00)');
done();
});
it('should round numbers', function(done) {
should(BrM.finance('1.1234')).be.eql('1.12');
should(BrM.finance(1.1234)).be.eql('1.12');
should(BrM.finance('-1.1234')).be.eql('(1.12)');
should(BrM.finance(-1.1234)).be.eql('(1.12)');
should(BrM.finance('1.1274')).be.eql('1.13');
should(BrM.finance(1.1274)).be.eql('1.13');
should(BrM.finance('-1.1274')).be.eql('(1.13)');
should(BrM.finance(-1.1274)).be.eql('(1.13)');
done();
});
it('should change precision', function(done) {
should(BrM.finance('123.1237123', 3)).be.eql('123.124');
should(BrM.finance(0.6234,0)).be.eql('1');
should(BrM.finance(123555.6234,-1)).be.eql('123555.62');
should(BrM.finance('-123.1237123', 3)).be.eql('(123.124)');
should(BrM.finance(-0.6234,0)).be.eql('(1)');
should(BrM.finance(-123555.6234,-1)).be.eql('(123555.62)');
done();
});
it('should change separators', function(done) {
should(BrM.finance('9123.1237123', 3, ',', '.')).be.eql('9.123,124');
should(BrM.finance(0.6234,0, ',', '.')).be.eql('1');
should(BrM.finance(87123555.6234,-1, ',', '.')).be.eql('87.123.555,62');
should(BrM.finance('-9123.1237123', 3, ',', '.')).be.eql('(9.123,124)');
should(BrM.finance(-0.6234,0, ',', '.')).be.eql('(1)');
should(BrM.finance(-87123555.6234,-1, ',', '.')).be.eql('(87.123.555,62)');
done();
});
it('should mask invalid numbers to 0.00', function(done) {
should(BrM.finance('0')).be.eql('0.00');
should(BrM.finance('-0')).be.eql('0.00');
should(BrM.finance('')).be.eql('0.00');
should(BrM.finance(undefined)).be.eql('0.00');
should(BrM.finance(null)).be.eql('0.00');
should(BrM.finance()).be.eql('0.00');
should(BrM.finance('a')).be.eql('0.00');
should(BrM.finance(' ')).be.eql('0.00');
should(BrM.finance('123a')).be.eql('123.00');
should(BrM.finance('123.a.1231')).be.eql('123.00');
should(BrM.finance('1.1256a.1231')).be.eql('1.13');
done();
});
});