Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Add notEmptyString validation #17
Browse files Browse the repository at this point in the history
  • Loading branch information
karrot-farmer committed Mar 9, 2018
1 parent 7d9988e commit 6065e02
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/utils/ValidationUtils.js
Original file line number Diff line number Diff line change
@@ -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;
}
29 changes: 29 additions & 0 deletions test/validationutils_test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 6065e02

Please sign in to comment.