RepoPilot

What edge cases (negative, NaN, Infinity) are tested?

About sindresorhus/pretty-bytes · 2 messages · last activity 7/13/2026

Question

What edge cases (negative, NaN, Infinity) are tested?

RepoPilot

The repository has comprehensive edge case testing for invalid inputs and special numeric values:

Invalid Input Types [test.js:L1-L40]:

  • Empty string, non-numeric strings, null, and boolean true all throw errors
  • Number.NaN, Number.POSITIVE_INFINITY, and Number.NEGATIVE_INFINITY all throw errors

Negative Numbers [test.js:L51-L60]:

  • Negative decimals: -0.4, -0.7, -10.1
  • Negative integers: -999, -1001
  • Negative bigints: -999n, -1001n
  • All format correctly with a minus sign

Special Cases with Options:

  • Signed option with zero [test.js:L125]: prettyBytes(0, {signed: true}) returns ' 0 B' (space instead of plus sign for alignment)
  • Negative numbers with fixedWidth [test.js:L329]: prettyBytes(-1337, {fixedWidth: 8}) returns '-1.34 kB' (no padding when output exceeds width)
  • Very small decimals [test.js:L328]: prettyBytes(0.5, {fixedWidth: 8}) returns ' 0.5 B'

Invalid fixedWidth Values [test.js:L307-L325]:

  • Negative: -5 throws error
  • Number.POSITIVE_INFINITY throws error
  • Number.NaN throws error
  • Non-integer floats: 3.5 throws error
  • Non-number types: string '10' throws error
  • Values exceeding Number.MAX_SAFE_INTEGER throw error

The tests ensure the function rejects invalid inputs but handles legitimate negative numbers and decimal values gracefully.

FOLLOW_UPS:

  • How does the signed option change output formatting?
  • What's the difference between binary and SI prefix modes?
  • How does locale affect number formatting in pretty-bytes?

Want to ask your own question?

Open chat for sindresorhus/pretty-bytes

Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/pretty-bytes. AI answers can be incomplete or stale — verify before relying on them.