From c273b2a00df474338a6dd29993dbb95d3fb60484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Carneiro?= Date: Tue, 6 Mar 2018 00:32:07 -0300 Subject: [PATCH 1/2] included a new zip-code test which checks empty string. Commit also contains fix that makes the code pass. --- __tests__/zip-code.mask.test.js | 10 +++++++++- lib/masks/zip-code.mask.js | 4 ++-- package-lock.json | 23 +++++++++++------------ package.json | 7 ++++++- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/__tests__/zip-code.mask.test.js b/__tests__/zip-code.mask.test.js index 40da9ce1..3d7641d4 100644 --- a/__tests__/zip-code.mask.test.js +++ b/__tests__/zip-code.mask.test.js @@ -51,4 +51,12 @@ test('11111111 results 11111-111 and raw value 11111111', () => { expect(received).toBe(expected); expect(receivedRawValue).toBe(expectedRawValue); -}); \ No newline at end of file +}); + +test('empty string is not valid', () => { + var mask = new ZipCodeMask(); + var received = mask.getValue(''); + var isValid = mask.validate(received); + + expect(isValid).toBe(false) +}); diff --git a/lib/masks/zip-code.mask.js b/lib/masks/zip-code.mask.js index 28c9c192..55cdb0dc 100644 --- a/lib/masks/zip-code.mask.js +++ b/lib/masks/zip-code.mask.js @@ -19,6 +19,6 @@ export default class ZipCodeMask extends BaseMask { return value.length === ZIP_CODE_MASK.length; } - return true; + return (value.length > 0); } -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index e28cb996..7f72966f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,7 @@ { "name": "react-native-masked-text", - "version": "1.6.4", + "version": "1.6.5", "lockfileVersion": 1, - "requires": true, "dependencies": { "abab": { "version": "1.0.4", @@ -4075,6 +4074,16 @@ "tweetnacl": "0.14.5" } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "dev": true, + "optional": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, "string-length": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/string-length/-/string-length-1.0.1.tgz", @@ -4095,16 +4104,6 @@ "strip-ansi": "3.0.1" } }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "optional": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", diff --git a/package.json b/package.json index f39b1237..1c20a668 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,12 @@ "type": "git", "url": "git+https://github.com/benhurott/react-native-masked-text.git" }, - "keywords": ["mask", "text", "textinput", "react-native"], + "keywords": [ + "mask", + "text", + "textinput", + "react-native" + ], "author": "Ben-hur Santos Ott", "license": "ISC", "bugs": { From d71a50121f61c133dd2bcc017140051c32eeea76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Carneiro?= Date: Tue, 6 Mar 2018 00:36:07 -0300 Subject: [PATCH 2/2] included a new zip-code test which checks empty string. Commit also contains fix that makes the code pass. --- __tests__/zip-code.mask.test.js | 10 +++++++++- lib/masks/zip-code.mask.js | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/__tests__/zip-code.mask.test.js b/__tests__/zip-code.mask.test.js index 40da9ce1..3d7641d4 100644 --- a/__tests__/zip-code.mask.test.js +++ b/__tests__/zip-code.mask.test.js @@ -51,4 +51,12 @@ test('11111111 results 11111-111 and raw value 11111111', () => { expect(received).toBe(expected); expect(receivedRawValue).toBe(expectedRawValue); -}); \ No newline at end of file +}); + +test('empty string is not valid', () => { + var mask = new ZipCodeMask(); + var received = mask.getValue(''); + var isValid = mask.validate(received); + + expect(isValid).toBe(false) +}); diff --git a/lib/masks/zip-code.mask.js b/lib/masks/zip-code.mask.js index 28c9c192..55cdb0dc 100644 --- a/lib/masks/zip-code.mask.js +++ b/lib/masks/zip-code.mask.js @@ -19,6 +19,6 @@ export default class ZipCodeMask extends BaseMask { return value.length === ZIP_CODE_MASK.length; } - return true; + return (value.length > 0); } -} \ No newline at end of file +}