1- import { unbreakableGap } from '../../utils' ;
1+ import { UNBREAKABLE_GAP } from '../../utils' ;
22import { formatBytes } from '../formatBytes' ;
33
44describe ( 'formatBytes' , ( ) => {
55 it ( 'should work with only value' , ( ) => {
6- expect ( formatBytes ( { value : 100 } ) ) . toBe ( `100${ unbreakableGap } B` ) ;
7- expect ( formatBytes ( { value : 100_000 } ) ) . toBe ( `100${ unbreakableGap } KB` ) ;
8- expect ( formatBytes ( { value : 100_000_000 } ) ) . toBe ( `100${ unbreakableGap } MB` ) ;
9- expect ( formatBytes ( { value : 100_000_000_000 } ) ) . toBe ( `100${ unbreakableGap } GB` ) ;
10- expect ( formatBytes ( { value : 100_000_000_000_000 } ) ) . toBe ( `100${ unbreakableGap } TB` ) ;
6+ expect ( formatBytes ( { value : 100 } ) ) . toBe ( `100${ UNBREAKABLE_GAP } B` ) ;
7+ expect ( formatBytes ( { value : 100_000 } ) ) . toBe ( `100${ UNBREAKABLE_GAP } KB` ) ;
8+ expect ( formatBytes ( { value : 100_000_000 } ) ) . toBe ( `100${ UNBREAKABLE_GAP } MB` ) ;
9+ expect ( formatBytes ( { value : 100_000_000_000 } ) ) . toBe ( `100${ UNBREAKABLE_GAP } GB` ) ;
10+ expect ( formatBytes ( { value : 100_000_000_000_000 } ) ) . toBe ( `100${ UNBREAKABLE_GAP } TB` ) ;
1111 } ) ;
1212 it ( 'should convert to size' , ( ) => {
1313 expect ( formatBytes ( { value : 100_000 , size : 'b' } ) ) . toBe (
14- `100${ unbreakableGap } 000${ unbreakableGap } B` ,
14+ `100${ UNBREAKABLE_GAP } 000${ UNBREAKABLE_GAP } B` ,
1515 ) ;
1616 expect ( formatBytes ( { value : 100_000_000_000_000 , size : 'gb' } ) ) . toBe (
17- `100${ unbreakableGap } 000${ unbreakableGap } GB` ,
17+ `100${ UNBREAKABLE_GAP } 000${ UNBREAKABLE_GAP } GB` ,
1818 ) ;
1919 } ) ;
2020 it ( 'should convert without labels' , ( ) => {
2121 expect ( formatBytes ( { value : 100_000 , size : 'b' , withSizeLabel : false } ) ) . toBe (
22- `100${ unbreakableGap } 000` ,
22+ `100${ UNBREAKABLE_GAP } 000` ,
2323 ) ;
2424 expect ( formatBytes ( { value : 100_000_000_000_000 , size : 'gb' , withSizeLabel : false } ) ) . toBe (
25- `100${ unbreakableGap } 000` ,
25+ `100${ UNBREAKABLE_GAP } 000` ,
2626 ) ;
2727 } ) ;
2828 it ( 'should convert to speed' , ( ) => {
2929 expect ( formatBytes ( { value : 100_000 , withSpeedLabel : true } ) ) . toBe (
30- `100${ unbreakableGap } KB/s` ,
30+ `100${ UNBREAKABLE_GAP } KB/s` ,
3131 ) ;
3232 expect ( formatBytes ( { value : 100_000 , size : 'b' , withSpeedLabel : true } ) ) . toBe (
33- `100${ unbreakableGap } 000${ unbreakableGap } B/s` ,
33+ `100${ UNBREAKABLE_GAP } 000${ UNBREAKABLE_GAP } B/s` ,
3434 ) ;
3535 } ) ;
3636 it ( 'should return fixed amount of significant digits' , ( ) => {
3737 expect ( formatBytes ( { value : 99_000 , significantDigits : 2 } ) ) . toEqual (
38- `99${ unbreakableGap } 000${ unbreakableGap } B` ,
38+ `99${ UNBREAKABLE_GAP } 000${ UNBREAKABLE_GAP } B` ,
3939 ) ;
4040 expect ( formatBytes ( { value : 100_000 , significantDigits : 2 } ) ) . toEqual (
41- `100${ unbreakableGap } KB` ,
41+ `100${ UNBREAKABLE_GAP } KB` ,
4242 ) ;
4343 expect ( formatBytes ( { value : 99_000_000_000_000 , significantDigits : 2 } ) ) . toEqual (
44- `99${ unbreakableGap } 000${ unbreakableGap } GB` ,
44+ `99${ UNBREAKABLE_GAP } 000${ UNBREAKABLE_GAP } GB` ,
4545 ) ;
4646 expect ( formatBytes ( { value : 100_000_000_000_000 , significantDigits : 2 } ) ) . toEqual (
47- `100${ unbreakableGap } TB` ,
47+ `100${ UNBREAKABLE_GAP } TB` ,
4848 ) ;
4949 } ) ;
5050 it ( 'should return empty string on invalid data' , ( ) => {
@@ -55,12 +55,12 @@ describe('formatBytes', () => {
5555 expect ( formatBytes ( { value : '123qwe' } ) ) . toEqual ( '' ) ;
5656 } ) ;
5757 it ( 'should work with precision' , ( ) => {
58- expect ( formatBytes ( { value : 123.123 , precision : 2 } ) ) . toBe ( `123${ unbreakableGap } B` ) ;
59- expect ( formatBytes ( { value : 12.123 , precision : 2 } ) ) . toBe ( `12${ unbreakableGap } B` ) ;
60- expect ( formatBytes ( { value : 1.123 , precision : 2 } ) ) . toBe ( `1.1${ unbreakableGap } B` ) ;
61- expect ( formatBytes ( { value : 0.123 , precision : 2 } ) ) . toBe ( `0.12${ unbreakableGap } B` ) ;
62- expect ( formatBytes ( { value : 0.012 , precision : 2 } ) ) . toBe ( `0.01${ unbreakableGap } B` ) ;
63- expect ( formatBytes ( { value : 0.001 , precision : 2 } ) ) . toBe ( `0${ unbreakableGap } B` ) ;
64- expect ( formatBytes ( { value : 0 , precision : 2 } ) ) . toBe ( `0${ unbreakableGap } B` ) ;
58+ expect ( formatBytes ( { value : 123.123 , precision : 2 } ) ) . toBe ( `123${ UNBREAKABLE_GAP } B` ) ;
59+ expect ( formatBytes ( { value : 12.123 , precision : 2 } ) ) . toBe ( `12${ UNBREAKABLE_GAP } B` ) ;
60+ expect ( formatBytes ( { value : 1.123 , precision : 2 } ) ) . toBe ( `1.1${ UNBREAKABLE_GAP } B` ) ;
61+ expect ( formatBytes ( { value : 0.123 , precision : 2 } ) ) . toBe ( `0.12${ UNBREAKABLE_GAP } B` ) ;
62+ expect ( formatBytes ( { value : 0.012 , precision : 2 } ) ) . toBe ( `0.01${ UNBREAKABLE_GAP } B` ) ;
63+ expect ( formatBytes ( { value : 0.001 , precision : 2 } ) ) . toBe ( `0${ UNBREAKABLE_GAP } B` ) ;
64+ expect ( formatBytes ( { value : 0 , precision : 2 } ) ) . toBe ( `0${ UNBREAKABLE_GAP } B` ) ;
6565 } ) ;
6666} ) ;
0 commit comments