|
|
@@ -0,0 +1,55 @@ |
|
|
|
import * as fc from 'fast-check' |
|
|
|
import formatFileSize from './formatFileSize' |
|
|
|
|
|
|
|
it('should exist', () => { |
|
|
|
expect(formatFileSize).toBeDefined() |
|
|
|
}) |
|
|
|
|
|
|
|
it('should be a function', () => { |
|
|
|
expect(typeof formatFileSize).toBe('function') |
|
|
|
}) |
|
|
|
|
|
|
|
it('should take 1 argument', () => { |
|
|
|
expect(formatFileSize).toHaveLength(1) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('on numeric arguments', () => { |
|
|
|
it('should format values of |x| < 1000', () => { |
|
|
|
fc.assert( |
|
|
|
fc.property( |
|
|
|
fc.integer().filter(v => Math.abs(v) < 1000), |
|
|
|
v => { |
|
|
|
expect(formatFileSize(v)).toMatch(/^-?\d+ B$/) |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
|
|
|
|
it('should format values of |x| >= 1000', () => { |
|
|
|
fc.assert( |
|
|
|
fc.property( |
|
|
|
fc.integer().filter(v => Math.abs(v) >= 1000), |
|
|
|
v => { |
|
|
|
expect(formatFileSize(v)).toMatch(/^-?\d+\.\d\d .B$/) |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
|
|
|
|
it('should throw an error on NaN', () => { |
|
|
|
expect(() => formatFileSize(NaN)).toThrow(RangeError) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe('on non-numeric arguments', () => { |
|
|
|
it('should throw an error', () => { |
|
|
|
fc.assert( |
|
|
|
fc.property( |
|
|
|
fc.anything().filter(v => typeof v !== 'number'), |
|
|
|
v => { |
|
|
|
expect(() => formatFileSize(v)).toThrow(TypeError) |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |