From 6065e02749ab0665c052ab81b1845409ddce12ce Mon Sep 17 00:00:00 2001 From: kujyp Date: Fri, 9 Mar 2018 16:18:26 +0900 Subject: [PATCH] Add notEmptyString validation #17 --- src/utils/ValidationUtils.js | 20 ++++++++++++++++++++ test/validationutils_test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/utils/ValidationUtils.js create mode 100644 test/validationutils_test.js diff --git a/src/utils/ValidationUtils.js b/src/utils/ValidationUtils.js new file mode 100644 index 0000000..b88bdce --- /dev/null +++ b/src/utils/ValidationUtils.js @@ -0,0 +1,20 @@ + +export function notEmptyString(data) { + console.log("data=", data); + + if (data === undefined || data == null) { + return false; + } + + if (data == "") { + return false; + } + + const spaceRegix = /^ +$/; + + if (spaceRegix.test(data)) { + return false; + } + + return true; +} diff --git a/test/validationutils_test.js b/test/validationutils_test.js new file mode 100644 index 0000000..a99f889 --- /dev/null +++ b/test/validationutils_test.js @@ -0,0 +1,29 @@ +const expect = require("chai").expect; +const notEmptyString = require("../src/utils/ValidationUtils").notEmptyString; + + +describe('notEmptyString', () => { + it('should notEmptyString with notEmptyString return true', () => { + expect( + notEmptyString("a") + ).to.equal(true); + }); + + it('should notEmptyString with emptyString return false', () => { + expect( + notEmptyString("") + ).to.equal(false); + }); + + it('should notEmptyString with undefined return false', () => { + expect( + notEmptyString(undefined) + ).to.equal(false); + }); + + it('should notEmptyString with onlySpace return false', () => { + expect( + notEmptyString(" ") + ).to.equal(false); + }); +}); \ No newline at end of file