|
- import * as fc from 'fast-check'
- import formatRawFileSize from './formatRawFileSize'
-
- it('should exist', () => {
- expect(formatRawFileSize).toBeDefined()
- })
-
- it('should be a function', () => {
- expect(typeof formatRawFileSize).toBe('function')
- })
-
- it('should take 1 argument', () => {
- expect(formatRawFileSize).toHaveLength(1)
- })
-
- it('should throw an error on non-numeric arguments', () => {
- fc.assert(
- fc.property(
- fc.anything().filter(v => typeof v !== 'number'),
- v => {
- expect(() => formatRawFileSize(v as number)).toThrow(TypeError)
- }
- )
- )
- })
-
- it('should throw an error on NaN', () => {
- expect(() => formatRawFileSize(NaN)).toThrow(RangeError)
- })
-
- it('should return string on numeric values', () => {
- fc.assert(
- fc.property(
- fc.integer(),
- v => {
- expect(typeof formatRawFileSize(v)).toBe('string')
- }
- )
- )
- })
-
- it('should format numeric values', () => {
- fc.assert(
- fc.property(
- fc.integer(),
- v => {
- expect(formatRawFileSize(v)).toMatch(/^-?\d[,\d]* .?B$/)
- }
- )
- )
- })
|