Skip to main content
Back to Elite Events

Elite Events Documentation

Technical documentation, guides, and API references for the Elite Events platform.

Test Coverage Reports/Formatting Utilities

Formatting Utilities Test Coverage

Last Updated: November 28, 2025 Status: Complete Coverage: 100% (Statements, Branches, Functions, Lines)


Overview

This document provides comprehensive test coverage details for the formatting utilities in the Elite Events application. The formatting utilities are critical for ensuring consistent display of numbers, currency, percentages, and text throughout the application.


Table of Contents

  1. Summary
  2. Test Files
  3. Coverage Metrics
  4. Format.ts Tests
  5. Utils.ts Tests
  6. Edge Cases Covered
  7. Running the Tests
  8. Key Findings

Summary

Total Tests Written: 86 Test Files: 2 Utilities Tested: 8 functions Coverage: 100% across all metrics

Functions Under Test

format.ts (4 functions)

  • formatNumber() - Formats numbers with comma separators
  • formatCurrency() - Formats currency values in USD
  • formatPercentage() - Converts decimals to percentages
  • formatCompact() - Formats numbers in compact notation (K, M, B, T)

utils.ts (4 functions)

  • cn() - Tailwind CSS class name merger
  • formatCurrency() - Full Intl.NumberFormat implementation with multi-currency support
  • truncate() - Text truncation with custom suffix
  • sleep() - Promise-based delay utility

Test Files

Location

src/lib/__tests__/format.test.ts
src/lib/__tests__/utils.test.ts

Source Files

src/lib/format.ts
src/lib/utils.ts

Coverage Metrics

Overall Coverage

-----------|---------|----------|---------|---------|-------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------|---------|----------|---------|---------|-------------------
All files  |     100 |      100 |     100 |     100 |
 format.ts |     100 |      100 |     100 |     100 |
 utils.ts  |     100 |      100 |     100 |     100 |
-----------|---------|----------|---------|---------|-------------------

Test Execution Results

Test Suites: 2 passed, 2 total
Tests:       86 passed, 86 total
Time:        ~2.6 seconds

Format.ts Tests

Test Structure (45 tests)

formatNumber Tests (12 tests)

  1. Basic Formatting

    • Formats integers with comma separators
    • Formats decimals with specified precision
    • Handles zero decimal places by default
  2. Numeric Range

    • Handles small numbers (0, 1, 99)
    • Handles large numbers (billions)
    • Handles negative numbers
  3. Edge Cases

    • Handles Infinity (∞)
    • Handles -Infinity (-∞)
    • Handles NaN
    • Handles very large decimal places (up to 8)
    • Handles zero with decimal places
    • Decimal precision edge cases (rounding)

Example Tests:

expect(formatNumber(1234)).toBe("1,234");
expect(formatNumber(1234.56, 2)).toBe("1,234.56");
expect(formatNumber(Infinity)).toBe("∞");
expect(formatNumber(-1234.56, 2)).toBe("-1,234.56");

formatCurrency Tests (11 tests)

  1. Standard Formatting

    • Formats with dollar sign and default 2 decimals
    • Handles zero value
    • Handles small amounts (cents)
    • Handles large amounts (billions)
  2. Customization

    • Respects custom decimal places
    • Handles zero decimals for whole amounts
  3. Edge Cases

    • Handles negative amounts
    • Handles very large currency amounts (999 billion)
    • Handles fractional cents with rounding
    • Handles Infinity ($∞)
    • Handles NaN ($NaN)
    • Handles more than 2 decimal places

Example Tests:

expect(formatCurrency(1234.56)).toBe("$1,234.56");
expect(formatCurrency(0.99)).toBe("$0.99");
expect(formatCurrency(1.995, 2)).toBe("$2.00");
expect(formatCurrency(Infinity)).toBe("$∞");

formatPercentage Tests (12 tests)

  1. Standard Conversion

    • Converts decimal to percentage
    • Handles zero
    • Handles values greater than 1 (>100%)
  2. Precision

    • Handles decimal precision (1, 2 decimals)
    • Handles small percentages (0.1%, 0.01%)
  3. Edge Cases

    • Handles negative percentages
    • Handles very large percentages (1,000%, 10,000%)
    • Handles very small percentages with precision
    • Handles Infinity (∞%)
    • Handles NaN (NaN%)
    • Handles rounding at boundaries

Example Tests:

expect(formatPercentage(0.15)).toBe("15%");
expect(formatPercentage(0.1234, 2)).toBe("12.34%");
expect(formatPercentage(10)).toBe("1,000%");
expect(formatPercentage(Infinity)).toBe("∞%");

formatCompact Tests (10 tests)

  1. Compact Notation

    • Formats thousands as K
    • Formats millions as M
    • Formats billions as B
    • Formats trillions as T
  2. Boundary Cases

    • Does not compact small numbers (<1000)
    • Handles edge case numbers near boundaries
    • Handles very small positive numbers
  3. Special Values

    • Handles negative numbers (-1.2K, -1M)
    • Handles Infinity (∞)
    • Handles -Infinity (-∞)

Example Tests:

expect(formatCompact(1234)).toBe("1.2K");
expect(formatCompact(1234567)).toBe("1.2M");
expect(formatCompact(1234567890)).toBe("1.2B");
expect(formatCompact(1234567890123)).toBe("1.2T");
expect(formatCompact(Infinity)).toBe("∞");

Utils.ts Tests

Test Structure (41 tests)

cn (Class Name Merger) Tests (12 tests)

  1. Basic Functionality

    • Merges multiple class strings
    • Handles Tailwind class conflicts (later value wins)
    • Handles conditional classes
    • Filters out falsy values
  2. Data Structures

    • Handles array of classes
    • Handles objects with multiple keys
    • Handles deeply nested structures
  3. Edge Cases

    • Handles empty input
    • Handles duplicate classes
    • Handles very long class strings
    • Merges complex Tailwind patterns
    • Properly merges responsive classes (md:, lg:)

Example Tests:

expect(cn("px-2", "px-4")).toBe("px-4");
expect(cn("base", true && "conditional")).toContain("conditional");
expect(cn({ "px-2": true, "text-red": false })).toContain("px-2");

formatCurrency (Intl Implementation) Tests (11 tests)

  1. Standard Formatting

    • Formats USD currency by default
    • Handles zero
    • Handles small decimal values
  2. Multi-Currency

    • Formats with different currencies (EUR, GBP, JPY)
  3. Edge Cases

    • Handles negative values
    • Handles large values
    • Handles very large numbers (999 billion)
    • Handles fractional cents with rounding
    • Handles Infinity (contains ∞)
    • Handles NaN (contains NaN)

Example Tests:

expect(formatCurrency(1234.56)).toBe("$1,234.56");
expect(formatCurrency(100, "GBP")).toContain("100.00");
expect(formatCurrency(1.995)).toBe("$2.00");

truncate Tests (13 tests)

  1. Basic Truncation

    • Truncates text longer than length
    • Does not truncate text shorter than length
    • Does not truncate text equal to length
  2. Customization

    • Uses custom suffix
    • Handles very long suffix
  3. Edge Cases

    • Handles empty string
    • Handles zero length
    • Handles negative length
    • Handles only whitespace (both within and exceeding length)
    • Handles unicode characters (emoji)
    • Handles multi-byte unicode correctly (Chinese characters)
    • Handles special characters (newlines, tabs)
    • Preserves exact length text without suffix

Example Tests:

expect(truncate("Hello World", 5)).toBe("Hello...");
expect(truncate("Hello", 5)).toBe("Hello");
expect(truncate("Hello World", 5, "…")).toBe("Hello…");
expect(truncate("Hello 👋 World", 8)).toBe("Hello 👋...");

sleep Tests (5 tests)

  1. Timing

    • Resolves after specified time
    • Handles zero delay
  2. Promise Behavior

    • Returns a promise
    • Resolves with undefined

Example Tests:

await sleep(50);
expect(elapsed).toBeGreaterThanOrEqual(45);

const result = sleep(1);
expect(result).toBeInstanceOf(Promise);

Edge Cases Covered

Numerical Edge Cases

  • Infinity: All number formatting functions handle Infinity
  • -Infinity: All number formatting functions handle negative Infinity
  • NaN: All number formatting functions handle NaN
  • Zero: All functions handle zero correctly
  • Negative numbers: All functions handle negative values
  • Very large numbers: Tested up to 999 billion
  • Very small numbers: Tested down to 0.00001
  • Fractional rounding: Proper handling of 1.995 → 2.00

String Edge Cases

  • Empty strings: Handled correctly
  • Unicode characters: Emoji and multi-byte characters tested
  • Special characters: Newlines, tabs, etc.
  • Whitespace-only strings: Both within and exceeding length
  • Negative length: Edge case for truncate function
  • Zero length: Edge case for truncate function

Class Name Merger Edge Cases

  • Empty input: Returns empty string
  • Falsy values: Filtered out correctly
  • Conflicting classes: Later value wins
  • Deeply nested structures: Flattened correctly
  • Duplicate classes: Deduplicated
  • Very long class strings: Handled efficiently
  • Responsive classes: Properly merged

Promise/Async Edge Cases

  • Zero delay: Handled correctly
  • Promise resolution: Returns undefined as expected
  • Timing variance: Tests allow for system timing variance

Running the Tests

Individual Test Files

# Test format.ts utilities
npm test -- src/lib/__tests__/format.test.ts --coverage --collectCoverageFrom='src/lib/format.ts'

# Test utils.ts utilities
npm test -- src/lib/__tests__/utils.test.ts --coverage --collectCoverageFrom='src/lib/utils.ts'

Combined Test Run

# Test all formatting utilities
npm test -- "src/lib/__tests__/(format|utils).test.ts" --coverage --collectCoverageFrom='src/lib/{format,utils}.ts'

Watch Mode

# Run tests in watch mode for development
npm test -- --watch src/lib/__tests__/format.test.ts
npm test -- --watch src/lib/__tests__/utils.test.ts

Key Findings

Strengths

  1. 100% Coverage: All statements, branches, functions, and lines are covered
  2. Comprehensive Edge Cases: Tests cover Infinity, NaN, negative numbers, and boundary conditions
  3. Real-World Scenarios: Tests include practical use cases like currency rounding, text truncation with unicode
  4. Fast Execution: All 86 tests run in ~2.6 seconds
  5. Clear Test Organization: Tests are well-organized into logical describe blocks
  6. Excellent Documentation: Each test has clear, descriptive names

Test Quality Metrics

  • Test Coverage: 100%
  • Edge Case Coverage: Excellent (includes Infinity, NaN, unicode, etc.)
  • Boundary Testing: Comprehensive (zero, negative, very large/small numbers)
  • Error Handling: All special values handled (Infinity, NaN)
  • Documentation: Clear test names and comments
  • Maintainability: Well-structured with describe blocks

Areas of Excellence

  1. Infinity and NaN Handling: All numeric formatting functions properly handle these special JavaScript values
  2. Unicode Support: Truncate function tested with emoji and multi-byte characters
  3. Currency Precision: Proper rounding tested (1.995 → $2.00)
  4. Compact Notation: Full range tested from thousands (K) to trillions (T)
  5. Tailwind Class Merging: Complex patterns and responsive classes properly tested

Test Breakdown by Category

Number Formatting (12 tests)

  • Basic formatting: 3 tests
  • Numeric ranges: 3 tests
  • Edge cases: 6 tests

Currency Formatting (22 tests)

  • format.ts currency: 11 tests
  • utils.ts currency: 11 tests
  • Multi-currency support: 3 tests

Percentage Formatting (12 tests)

  • Standard conversion: 3 tests
  • Precision handling: 2 tests
  • Edge cases: 7 tests

Compact Notation (10 tests)

  • Notation levels: 4 tests
  • Boundary cases: 3 tests
  • Special values: 3 tests

Text Truncation (13 tests)

  • Basic truncation: 3 tests
  • Customization: 2 tests
  • Edge cases: 8 tests

Class Name Merging (12 tests)

  • Basic functionality: 4 tests
  • Data structures: 3 tests
  • Edge cases: 5 tests

Async Utilities (5 tests)

  • Timing: 2 tests
  • Promise behavior: 3 tests

Recommendations

Maintenance

  1. Keep tests updated: When adding new formatting functions, add corresponding tests
  2. Monitor coverage: Run coverage reports regularly to ensure 100% coverage is maintained
  3. Add regression tests: If bugs are found, add tests to prevent regression

Future Enhancements

  1. Performance testing: Consider adding performance benchmarks for large datasets
  2. Localization testing: Add tests for different locales if internationalization is planned
  3. Integration tests: Test formatting utilities in context of actual components

Best Practices

  1. Run tests before commits: Use git hooks to ensure tests pass
  2. Review coverage reports: Check coverage when making changes
  3. Add tests for new features: Follow TDD approach for new formatting utilities


Conclusion

The formatting utilities for Elite Events have comprehensive test coverage with 86 tests achieving 100% coverage across all metrics. The tests cover a wide range of edge cases including special JavaScript values (Infinity, NaN), unicode characters, currency rounding, and boundary conditions. The test suite is well-organized, maintainable, and provides confidence in the reliability of these critical utility functions.


Last Updated: November 28, 2025 Test Count: 86 tests Coverage: 100% (Statements, Branches, Functions, Lines) Status: Complete and Passing

Documentation | Elite Events | Philip Rehberger