-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
37 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,54 @@ | ||
import { describe, expect, test } from 'bun:test'; | ||
import { formatPrice, type Currency } from './index'; | ||
import { formatPrice } from './index'; | ||
import type { Currency } from './index'; | ||
|
||
describe('formatPrice', () => { | ||
test('should format price with default locale and cents enabled', () => { | ||
const money = { amount: '1234.56', currencyCode: 'EUR' } satisfies Currency; | ||
const result = formatPrice(money); | ||
|
||
expect(result).toBe('1 234,56 €'); | ||
}); | ||
|
||
test('should format price with custom locale and cents enabled', () => { | ||
const money = { amount: '1234.56', currencyCode: 'USD' }satisfies Currency; | ||
const money = { amount: '1234.56', currencyCode: 'USD' } satisfies Currency; | ||
const result = formatPrice(money, 'en-US'); | ||
|
||
expect(result).toBe('$1,234.56'); | ||
}); | ||
|
||
test('should format price with quantity multiplier', () => { | ||
const money = { amount: '1234.56', currencyCode: 'USD' }satisfies Currency; | ||
const money = { amount: '1234.56', currencyCode: 'USD' } satisfies Currency; | ||
const result = formatPrice(money, 'en-US', 2); | ||
|
||
expect(result).toBe('$2,469.12'); | ||
}); | ||
|
||
test('should format price with cents disabled when applicable', () => { | ||
const money = { amount: '1234.00', currencyCode: 'USD' }satisfies Currency; | ||
const money = { amount: '1234.00', currencyCode: 'USD' } satisfies Currency; | ||
const result = formatPrice(money, 'en-US', 1, true); | ||
|
||
expect(result).toBe('$1,234'); | ||
}); | ||
|
||
test('should still include cents if the amount has fractional part even if disableCents is true', () => { | ||
const money = { amount: '1234.56', currencyCode: 'USD' }satisfies Currency; | ||
const money = { amount: '1234.56', currencyCode: 'USD' } satisfies Currency; | ||
const result = formatPrice(money, 'en-US', 1, true); | ||
|
||
expect(result).toBe('$1,234.56'); | ||
}); | ||
|
||
test('should format price correctly with a different currency code', () => { | ||
const money = { amount: '1234.56', currencyCode: 'GBP' }satisfies Currency; | ||
const money = { amount: '1234.56', currencyCode: 'GBP' } satisfies Currency; | ||
const result = formatPrice(money, 'en-GB'); | ||
|
||
expect(result).toBe('£1,234.56'); | ||
}); | ||
|
||
test('should handle large quantities correctly', () => { | ||
const money = { amount: '1000.00', currencyCode: 'EUR' }satisfies Currency; | ||
const money = { amount: '1000.00', currencyCode: 'EUR' } satisfies Currency; | ||
const result = formatPrice(money, 'fr', 100); | ||
|
||
expect(result).toBe('100 000,00 €'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export const RE_EMAIL = | ||
// eslint-disable-next-line unicorn/better-regex | ||
/^(([^\s"(),.:;<>@[\\\]]+(\.[^\s"(),.:;<>@[\\\]]+)*)|(".+"))@((\[(?:\d{1,3}\.){3}\d{1,3}\])|(([\da-z-]+\.)+[a-z]{2,}))$/i; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters