Skip to content

Commit fd2f06f

Browse files
committed
fix: tests
1 parent 6663d3f commit fd2f06f

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

src/utils/bytesParsers/__test__/formatBytes.test.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,37 @@ import {formatBytes} from '../formatBytes';
22

33
describe('formatBytes', () => {
44
it('should work with only value', () => {
5-
expect(formatBytes({value: 100})).toBe('100 B');
6-
expect(formatBytes({value: 100_000})).toBe('100 KB');
7-
expect(formatBytes({value: 100_000_000})).toBe('100 MB');
8-
expect(formatBytes({value: 100_000_000_000})).toBe('100 GB');
9-
expect(formatBytes({value: 100_000_000_000_000})).toBe('100 TB');
5+
expect(formatBytes({value: 100})).toBe('100\xa0B');
6+
expect(formatBytes({value: 100_000})).toBe('100\xa0KB');
7+
expect(formatBytes({value: 100_000_000})).toBe('100\xa0MB');
8+
expect(formatBytes({value: 100_000_000_000})).toBe('100\xa0GB');
9+
expect(formatBytes({value: 100_000_000_000_000})).toBe('100\xa0TB');
1010
});
1111
it('should convert to size', () => {
12-
expect(formatBytes({value: 100_000, size: 'b'})).toBe('100 000 B');
13-
expect(formatBytes({value: 100_000_000_000_000, size: 'gb'})).toBe('100 000 GB');
12+
expect(formatBytes({value: 100_000, size: 'b'})).toBe('100\xa0000\xa0B');
13+
expect(formatBytes({value: 100_000_000_000_000, size: 'gb'})).toBe('100\xa0000\xa0GB');
1414
});
1515
it('should convert without labels', () => {
16-
expect(formatBytes({value: 100_000, size: 'b', withSizeLabel: false})).toBe('100 000');
16+
expect(formatBytes({value: 100_000, size: 'b', withSizeLabel: false})).toBe('100\xa0000');
1717
expect(formatBytes({value: 100_000_000_000_000, size: 'gb', withSizeLabel: false})).toBe(
18-
'100 000',
18+
'100\xa0000',
1919
);
2020
});
2121
it('should convert to speed', () => {
22-
expect(formatBytes({value: 100_000, withSpeedLabel: true})).toBe('100 KB/s');
23-
expect(formatBytes({value: 100_000, size: 'b', withSpeedLabel: true})).toBe('100 000 B/s');
22+
expect(formatBytes({value: 100_000, withSpeedLabel: true})).toBe('100\xa0KB/s');
23+
expect(formatBytes({value: 100_000, size: 'b', withSpeedLabel: true})).toBe(
24+
'100\xa0000\xa0B/s',
25+
);
2426
});
2527
it('should return fixed amount of significant digits', () => {
26-
expect(formatBytes({value: 99_000, significantDigits: 2})).toEqual('99 000 B');
27-
expect(formatBytes({value: 100_000, significantDigits: 2})).toEqual('100 KB');
28-
expect(formatBytes({value: 99_000_000_000_000, significantDigits: 2})).toEqual('99 000 GB');
29-
expect(formatBytes({value: 100_000_000_000_000, significantDigits: 2})).toEqual('100 TB');
28+
expect(formatBytes({value: 99_000, significantDigits: 2})).toEqual('99\xa0000\xa0B');
29+
expect(formatBytes({value: 100_000, significantDigits: 2})).toEqual('100\xa0KB');
30+
expect(formatBytes({value: 99_000_000_000_000, significantDigits: 2})).toEqual(
31+
'99\xa0000\xa0GB',
32+
);
33+
expect(formatBytes({value: 100_000_000_000_000, significantDigits: 2})).toEqual(
34+
'100\xa0TB',
35+
);
3036
});
3137
it('should return empty string on invalid data', () => {
3238
expect(formatBytes({value: undefined})).toEqual('');
@@ -36,12 +42,12 @@ describe('formatBytes', () => {
3642
expect(formatBytes({value: '123qwe'})).toEqual('');
3743
});
3844
it('should work with precision', () => {
39-
expect(formatBytes({value: 123.123, precision: 2})).toBe('123 B');
40-
expect(formatBytes({value: 12.123, precision: 2})).toBe('12 B');
41-
expect(formatBytes({value: 1.123, precision: 2})).toBe('1.1 B');
42-
expect(formatBytes({value: 0.123, precision: 2})).toBe('0.12 B');
43-
expect(formatBytes({value: 0.012, precision: 2})).toBe('0.01 B');
44-
expect(formatBytes({value: 0.001, precision: 2})).toBe('0 B');
45-
expect(formatBytes({value: 0, precision: 2})).toBe('0 B');
45+
expect(formatBytes({value: 123.123, precision: 2})).toBe('123\xa0B');
46+
expect(formatBytes({value: 12.123, precision: 2})).toBe('12\xa0B');
47+
expect(formatBytes({value: 1.123, precision: 2})).toBe('1.1\xa0B');
48+
expect(formatBytes({value: 0.123, precision: 2})).toBe('0.12\xa0B');
49+
expect(formatBytes({value: 0.012, precision: 2})).toBe('0.01\xa0B');
50+
expect(formatBytes({value: 0.001, precision: 2})).toBe('0\xa0B');
51+
expect(formatBytes({value: 0, precision: 2})).toBe('0\xa0B');
4652
});
4753
});

0 commit comments

Comments
 (0)