Skip to content

Commit a35b171

Browse files
authored
fix: correct types for resolveCurrencyFormat (#139)
1 parent 1b1b86a commit a35b171

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/lib/number-format/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ export const resolveCurrencyFormat = resolveNumberFormatFactory(
355355
getCurrencyOptions,
356356
) as (
357357
locales?: Locale | Locale[],
358+
currency?: Currency,
358359
options?: Intl.NumberFormatOptions,
359360
) => NumberFormat | null;
360361

src/tests/format.spec.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,22 @@ describe('Format', () => {
5050
});
5151
});
5252

53+
it('should accept a custom currency', () => {
54+
const locale = 'xx-XX';
55+
const currency = 'XXX';
56+
const actual = formatCurrency(number, locale, currency);
57+
expect(actual).toBeString();
58+
expect(Intl.NumberFormat).toHaveBeenCalledWith(locale, {
59+
style: 'currency',
60+
currency,
61+
});
62+
});
63+
5364
it('should format as a unitless number if currency is not found', () => {
54-
const actual = formatCurrency(number, 'xx-XX');
65+
const locale = 'xx-XX';
66+
const actual = formatCurrency(number, locale);
5567
expect(actual).toBeString();
56-
expect(Intl.NumberFormat).toHaveBeenCalledWith('xx-XX', {
68+
expect(Intl.NumberFormat).toHaveBeenCalledWith(locale, {
5769
style: 'decimal',
5870
});
5971
});

src/tests/formatToParts.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,16 @@ describe('Format to parts', () => {
4949
currency: expect.any(String),
5050
});
5151
});
52+
53+
it('should accept a custom currency', () => {
54+
const locale = 'xx-XX';
55+
const currency = 'XXX';
56+
const actual = formatCurrencyToParts(number, locale, currency);
57+
expect(actual).toBeArray();
58+
expect(Intl.NumberFormat).toHaveBeenCalledWith(locale, {
59+
style: 'currency',
60+
currency,
61+
});
62+
});
5263
});
5364
});

src/tests/resolveFormat.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,16 @@ describe('Resolve format', () => {
3737
currency: expect.any(String),
3838
});
3939
});
40+
41+
it('should accept a custom currency', () => {
42+
const locale = 'xx-XX';
43+
const currency = 'XXX';
44+
const actual = resolveCurrencyFormat(locale, currency);
45+
expect(actual).toBeObject();
46+
expect(Intl.NumberFormat).toHaveBeenCalledWith(locale, {
47+
style: 'currency',
48+
currency,
49+
});
50+
});
4051
});
4152
});

0 commit comments

Comments
 (0)