-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.spec.js
50 lines (40 loc) 路 1.69 KB
/
index.spec.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
const { calculateTax, asyncCalculateTax } = require( './index.js' );
const { expect } = require('chai');
describe( 'calculateTax()', () => {
it( 'Should return 0 given an invalid number type', () => {
expect( calculateTax( 'ab' ) ).to.equal( 0 );
});
it( 'Should return 0 given a negative number', () => {
expect( calculateTax( -15 ) ).to.equal( 0 );
});
it( 'Should return 0 given a taxable income of 16,432', () => {
expect( calculateTax( 16432 ) ).to.equal( 0 );
});
it( 'Should return 3192 given a taxable income of 35,000', () => {
expect( calculateTax( 35000 ) ).to.equal( 3192 );
});
it( 'Should return 44772.25 given a taxable income of 154,798', () => {
expect( calculateTax( 154798 ) ).to.equal( 44772.26 );
});
it( 'Should return 15887.55 given a taxable income of 74,894', () => {
expect( calculateTax( 74894 ) ).to.equal( 15887.55 );
});
it( 'Should return 802793.05 given a taxable income of 1,843,769', () => {
expect( calculateTax( 1843769 ) ).to.equal( 802793.05 );
});
});
describe( 'asyncCalculateTax()', async () => {
it( 'Should throw an error given an invalid number type', async () => {
try {
await asyncCalculateTax( 'ab' );
} catch( err ) {
expect( err.message ).to.equal( "Invalid input" );
}
});
it( 'Should return 15887.55 given a taxable income of 74,894', async () => {
expect( await asyncCalculateTax( 74894 ) ).to.equal( 15887.55 );
});
it( 'Should return 802793.05 given a taxable income of 1,843,769', async () => {
expect( await asyncCalculateTax( 1843769 ) ).to.equal( 802793.05 );
});
});