Merge pull request #262 from vicdata4/fix/input-amount-locale

Fix: pass string instead of object in input-amount parser
This commit is contained in:
Joren Broekema 2019-09-02 09:38:13 +02:00 committed by GitHub
commit 1c697b10c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -60,7 +60,8 @@ function getParseMode(value) {
* @param {object} options Locale Options
*/
function parseWithLocale(value, options) {
const separator = getDecimalSeparator(options);
const locale = options && options.locale ? options.locale : null;
const separator = getDecimalSeparator(locale);
const regexNumberAndLocaleSeparator = new RegExp(`[0-9${separator}-]`, 'g');
let numberAndLocaleSeparator = value.match(regexNumberAndLocaleSeparator).join('');
if (separator === ',') {

View file

@ -145,4 +145,17 @@ describe('parseAmount()', () => {
it('returns undefined when value is empty string', () => {
expect(parseAmount('')).to.equal(undefined);
});
it('parseAmount with locale set and length is more than four', () => {
expect(
parseAmount('6,000', {
locale: 'gb-GB',
}),
).to.equal(6000);
expect(
parseAmount('6.000', {
locale: 'es-ES',
}),
).to.equal(6000);
});
});