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.

56 lines
1.2 KiB

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