Skip to content

Commit

Permalink
fix(allowEmpty): return empty string also when value is empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszgolder committed May 11, 2018
1 parent fa624f1 commit 894deeb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/__tests__/createNumberMask.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ describe('Number mask', () => {
expect(mask.format()).toBe('');
});

it('should be formatting as empty string when the value on the store is empty string and allowEmpty is true', () => {
const mask = createNumberMask({
prefix: 'p',
suffix: 's',
allowEmpty: true,
});

expect(mask.format('')).toBe('');
});

it('should update the stored value correctly', () => {
const prefix = 'prefix 1@,.';
const suffix = '1@,. suffix';
Expand Down
2 changes: 1 addition & 1 deletion src/createNumberMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default options => {

const format = storeValue => {
let number = storeValue;
if (number === undefined) {
if (number === undefined || number === '') {
if (allowEmpty) {
return '';
}
Expand Down

0 comments on commit 894deeb

Please sign in to comment.