-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8b4d6b
commit fec46c4
Showing
4 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
test/ | ||
.github/ | ||
src/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import Validator from "../src/Validator"; | ||
|
||
describe('Validator::email', () => { | ||
const rules = { | ||
name: 'email' | ||
} | ||
|
||
it('should not fail when field is not present', async (done) => { | ||
|
||
const v = await Validator.make({ | ||
data: { | ||
}, | ||
rules | ||
}) | ||
expect(v.fails()).toBe(false) | ||
expect(v.getErrors()).not.toHaveProperty('name') | ||
done() | ||
}) | ||
|
||
it('should fail for not email values', async (done) => { | ||
|
||
for (const input of ['', 'domain.com', 'some[at]domain.com', 'some@domain', 'some@domain.']) { | ||
const v = await Validator.make({ | ||
data: { | ||
name: input | ||
}, | ||
rules | ||
}) | ||
expect(v.fails()).toBe(true) | ||
expect(v.getErrors()).toHaveProperty('name') | ||
} | ||
done() | ||
}) | ||
|
||
it('should success for email values', async (done) => { | ||
|
||
const prefixes = ['john', 'john123', 'john_doe', 'john_doe_123'] | ||
const domains = ['.co', '.com', '.fr', '.sn', '.net', '.org', '.edu'] | ||
const inputs: string[] = [] | ||
for (const prefix of prefixes) { | ||
for (const domain of domains) { | ||
inputs.push(`${prefix}@domain${domain}`) | ||
} | ||
} | ||
for (const input of inputs) { | ||
const v = await Validator.make({ | ||
data: { | ||
name: input | ||
}, | ||
rules | ||
}) | ||
expect(v.fails()).toBe(false) | ||
expect(v.getErrors()).not.toHaveProperty('name') | ||
} | ||
done() | ||
}) | ||
|
||
it('should success for sub domain emails', async (done) => { | ||
|
||
const inputs = ['[email protected]', '[email protected]'] | ||
for (const input of inputs) { | ||
const v = await Validator.make({ | ||
data: { | ||
name: input | ||
}, | ||
rules | ||
}) | ||
expect(v.fails()).toBe(false) | ||
expect(v.getErrors()).not.toHaveProperty('name') | ||
} | ||
done() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Validator from "../src/Validator"; | ||
|
||
describe('Validator Core', () => { | ||
describe('::after hook', () => { | ||
|
||
}) | ||
}) |