lion/packages/input-amount/test/formatters.test.js
Manuel Martin b2f981db72 refactor: add package exports entry
This commit adds the exports entry in each package.json, exposing the public parts of each package and hiding the private ones.
2021-02-15 17:49:22 +01:00

75 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { expect } from '@open-wc/testing';
import { localize } from '@lion/localize';
import { localizeTearDown } from '@lion/localize/test-helpers';
import { formatAmount } from '../src/formatters.js';
describe('formatAmount()', () => {
afterEach(() => {
localizeTearDown();
});
it('formats number with options', async () => {
expect(
formatAmount(12.345678, {
locale: 'en-GB',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}),
).to.equal('12.35');
expect(
formatAmount(12.345678, {
locale: 'nl-NL',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}),
).to.equal('12,35');
expect(
formatAmount(12345678, {
locale: 'en-GB',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}),
).to.equal('12,345,678.00');
expect(
formatAmount(12345678, {
locale: 'nl-NL',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}),
).to.equal('12.345.678,00');
expect(
formatAmount(12.345678, {
locale: 'en-GB',
minimumFractionDigits: 0,
maximumFractionDigits: 1,
}),
).to.equal('12.3');
expect(
formatAmount(12.345678, {
locale: 'en-GB',
minimumFractionDigits: 3,
maximumFractionDigits: 3,
}),
).to.equal('12.346');
expect(
formatAmount(-12.345678, {
locale: 'en-GB',
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}),
).to.equal('12.35');
});
it('formats the right amount of fraction digits for a certain currency', async () => {
expect(formatAmount(123456.78, { locale: 'en-GB', currency: 'EUR' })).to.equal('123,456.78');
expect(formatAmount(123456.78, { locale: 'en-GB', currency: 'JOD' })).to.equal('123,456.780');
});
it('fallbacks to global locale and EUR by default', async () => {
localize.locale = 'en-GB';
expect(formatAmount(12345678)).to.equal('12,345,678.00');
localize.locale = 'nl-NL';
expect(formatAmount(12345678)).to.equal('12.345.678,00');
});
});