Skip to content

Commit

Permalink
fix: prevent setRawValue to convert 0 to empty string
Browse files Browse the repository at this point in the history
Closes #113
  • Loading branch information
Marzio Superina committed Jul 25, 2018
1 parent 7730ece commit 663499d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/finput.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ class Finput {
*/
setRawValue(val) {
let value;
if (!val) {
value = '';
} else if (typeof val === 'number' && !isNaN(val)) {
if (typeof val === 'number' && !isNaN(val)) {
value = helpers.rawToFormatted(val, this.options);
} else if (typeof val === 'string') {
value = val;
} else if (!val) {
value = '';
} else {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion test/jestConfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"setupTestFrameworkScriptFile": "./setupTests.js",
"testMatch": [
"**/specs/**/*.js"
"**/specs/**/*.js",
"**/unit/**/*.js"
],
"globals": {
"__baseUrl__": "http://localhost:3000"
Expand Down
22 changes: 22 additions & 0 deletions test/unit/setRawValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import finput from '../../src/finput';

describe('setRawValue', () => {

let element;
let destroy;

beforeEach(() => {
element = document.createElement('input');
destroy = finput(element);
});

afterEach(() => {
destroy();
});

it('when passed 0 sets value 0', () => {
element.setRawValue(0);
expect(element.value).toBe('0.00');
});

});

0 comments on commit 663499d

Please sign in to comment.