Useful methods for file-related functions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.0 KiB

  1. import * as fc from 'fast-check'
  2. import formatRawFileSize from './formatRawFileSize'
  3. it('should exist', () => {
  4. expect(formatRawFileSize).toBeDefined()
  5. })
  6. it('should be a function', () => {
  7. expect(typeof formatRawFileSize).toBe('function')
  8. })
  9. it('should take 1 argument', () => {
  10. expect(formatRawFileSize).toHaveLength(1)
  11. })
  12. it('should throw an error on non-numeric arguments', () => {
  13. fc.assert(
  14. fc.property(
  15. fc.anything().filter(v => typeof v !== 'number'),
  16. v => {
  17. expect(() => formatRawFileSize(v)).toThrow(TypeError)
  18. }
  19. )
  20. )
  21. })
  22. it('should throw an error on NaN', () => {
  23. expect(() => formatRawFileSize(NaN)).toThrow(RangeError)
  24. })
  25. it('should return string on numeric values', () => {
  26. fc.assert(
  27. fc.property(
  28. fc.integer(),
  29. v => {
  30. expect(typeof formatRawFileSize(v)).toBe('string')
  31. }
  32. )
  33. )
  34. })
  35. it('should format numeric values', () => {
  36. fc.assert(
  37. fc.property(
  38. fc.integer(),
  39. v => {
  40. expect(formatRawFileSize(v)).toMatch(/^-?\d[,\d]* .?B$/)
  41. }
  42. )
  43. )
  44. })