Skip to content

Conversation

@dylandepass
Copy link
Contributor

Summary

This PR fixes a critical bug in the formatPrice function. The old formatPrice logic compared prices as strings instead of numbers, which broke sale-price detection. Example: "9" is considered greater than "100" in a string comparison, even though 9 is obviously less than 100. The fix switches the comparisons to numeric by wrapping the values in parseFloat(), so sale prices resolve correctly again.

Changes

Core Implementation

Test Coverage

  • test/steps/render-body.test.js: Added comprehensive test suite with 206 test cases covering:
    • Null and empty cases
    • Regular pricing (no sale)
    • Sale pricing scenarios
    • String-to-number conversion edge cases
    • Invalid/NaN handling
    • Zero and negative price handling
    • Decimal precision and large numbers
  • ✅ Maintains 100% code coverage (270 tests passing, 100% coverage across all metrics)

Example

Before (Bug)

// String comparison: "9" > "100" (lexicographic)
formatPrice({ final: "9.99", regular: "100.00" })
// Incorrectly displayed as: $9.99 (regular price, no strikethrough)

After (Fixed)

// Numeric comparison: 9.99 < 100.00
formatPrice({ final: "9.99", regular: "100.00" })
// Correctly displayed as: $9.99 ($100.00) (with strikethrough on $100.00)

@dylandepass dylandepass requested a review from maxakuru November 25, 2025 15:40
@dylandepass dylandepass merged commit e6fd2b0 into main Nov 25, 2025
6 checks passed
@dylandepass dylandepass deleted the pricing-fix branch November 25, 2025 16:34
@github-actions
Copy link

🎉 This PR is included in version 1.9.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants