Skip to content

Commit

Permalink
fix: correct types for resolveCurrencyFormat (#139)
Browse files Browse the repository at this point in the history
connor-baer authored Nov 28, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1b1b86a commit a35b171
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib/number-format/index.ts
Original file line number Diff line number Diff line change
@@ -355,6 +355,7 @@ export const resolveCurrencyFormat = resolveNumberFormatFactory(
getCurrencyOptions,
) as (
locales?: Locale | Locale[],
currency?: Currency,
options?: Intl.NumberFormatOptions,
) => NumberFormat | null;

16 changes: 14 additions & 2 deletions src/tests/format.spec.ts
Original file line number Diff line number Diff line change
@@ -50,10 +50,22 @@ describe('Format', () => {
});
});

it('should accept a custom currency', () => {
const locale = 'xx-XX';
const currency = 'XXX';
const actual = formatCurrency(number, locale, currency);
expect(actual).toBeString();
expect(Intl.NumberFormat).toHaveBeenCalledWith(locale, {
style: 'currency',
currency,
});
});

it('should format as a unitless number if currency is not found', () => {
const actual = formatCurrency(number, 'xx-XX');
const locale = 'xx-XX';
const actual = formatCurrency(number, locale);
expect(actual).toBeString();
expect(Intl.NumberFormat).toHaveBeenCalledWith('xx-XX', {
expect(Intl.NumberFormat).toHaveBeenCalledWith(locale, {
style: 'decimal',
});
});
11 changes: 11 additions & 0 deletions src/tests/formatToParts.spec.ts
Original file line number Diff line number Diff line change
@@ -49,5 +49,16 @@ describe('Format to parts', () => {
currency: expect.any(String),
});
});

it('should accept a custom currency', () => {
const locale = 'xx-XX';
const currency = 'XXX';
const actual = formatCurrencyToParts(number, locale, currency);
expect(actual).toBeArray();
expect(Intl.NumberFormat).toHaveBeenCalledWith(locale, {
style: 'currency',
currency,
});
});
});
});
11 changes: 11 additions & 0 deletions src/tests/resolveFormat.spec.ts
Original file line number Diff line number Diff line change
@@ -37,5 +37,16 @@ describe('Resolve format', () => {
currency: expect.any(String),
});
});

it('should accept a custom currency', () => {
const locale = 'xx-XX';
const currency = 'XXX';
const actual = resolveCurrencyFormat(locale, currency);
expect(actual).toBeObject();
expect(Intl.NumberFormat).toHaveBeenCalledWith(locale, {
style: 'currency',
currency,
});
});
});
});

0 comments on commit a35b171

Please sign in to comment.