forked from bfintal/Counter-Up2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
48 lines (43 loc) · 2.02 KB
/
index.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
import {divideNumbers} from './index'
test('divideNumbers', () => {
const num = '1310.51';
const numFormatted = '1,310.51'; // jest will always use US for "toLocaleString()"
const nums = divideNumbers(num);
expect(nums).toEqual(expect.arrayContaining([numFormatted]));
expect(nums[nums.length - 1]).toBe(numFormatted);
expect(nums[0]).toBe('')
});
test('with unit', () => {
const unit = 'Mio';
const num = `1310.51 ${unit}`;
const numFormatted = `1,310.51 ${unit}`; // jest will always use US for "toLocaleString()"
const nums = divideNumbers(num);
expect(nums).toEqual(expect.arrayContaining([numFormatted]));
expect(nums[nums.length - 1]).toBe(numFormatted);
expect(nums[0]).toBe(` ${unit}`)
});
test('with abbreviated unit', () => {
const unit = 'Mio.';
const num = `1310.51 ${unit}`;
const numFormatted = `1,310.51 ${unit}`; // jest will always use US for "toLocaleString()"
const nums = divideNumbers(num);
expect(nums).toEqual(expect.arrayContaining([numFormatted]));
expect(nums[nums.length - 1]).toBe(numFormatted);
expect(nums[0]).toBe(` ${unit}`)
});
test('with unit no decimal', () => {
const unit = 'Mio.';
const num = `1310 ${unit}`;
const numFormatted = `1,310 ${unit}`; // jest will always use US for "toLocaleString()"
const nums = divideNumbers(num);
expect(nums).toEqual(expect.arrayContaining([numFormatted]));
expect(nums[nums.length - 1]).toBe(numFormatted);
expect(nums[0]).toBe(` ${unit}`)
});
test('more text', () => {
const num = `The biggest wildcat today is the Siberian Tiger. It can be more than 12 feet (3.6 m) long (about the size of a small car) and weigh up to 700 pounds (317 kg).`;
const numFormatted = `The biggest wildcat today is the Siberian Tiger. It can be more than 12 feet (3.6 m) long (about the size of a small car) and weigh up to 700 pounds (317 kg).`; // jest will always use US for "toLocaleString()"
const nums = divideNumbers(num);
expect(nums).toEqual(expect.arrayContaining([numFormatted]));
expect(nums[nums.length - 1]).toBe(numFormatted);
});