fix(input-amount): pass string instead of object in parser

This commit is contained in:
victorgh 2019-08-26 09:33:19 +02:00 committed by Joren Broekema
parent 41e12da90d
commit 7fb68ed7a3
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);
});
});