UNPKG

3.32 kBJavaScriptView Raw
1const expect = require('chai').expect;
2const validator = require(".");
3
4const validSupported =
5[
6 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org",
7 "01234567890@numbers-in-local.net",
8 "&'*+-./=?^_{}~@other-valid-characters-in-local.net",
9 "mixed-1234-in-{+^}-local@sld.net",
10 "a@single-character-in-local.org",
11 "one-character-third-level@a.example.com",
12 "single-character-in-sld@x.org",
13 "local@dash-in-sld.com",
14 "letters-in-sld@123.com",
15 "one-letter-sld@x.org",
16 "uncommon-tld@sld.museum",
17 "uncommon-tld@sld.travel",
18 "uncommon-tld@sld.mobi",
19 "country-code-tld@sld.uk",
20 "country-code-tld@sld.rw",
21 "local@sld.newTLD",
22 "the-total-length@of-an-entire-address.cannot-be-longer-than-two-hundred-and-fifty-four-characters.and-this-address-is-254-characters-exactly.so-it-should-be-valid.and-im-going-to-add-some-more-words-here.to-increase-the-lenght-blah-blah-blah-blah-bla.org",
23 "the-character-limit@for-each-part.of-the-domain.is-sixty-three-characters.this-is-exactly-sixty-three-characters-so-it-is-valid-blah-blah.com",
24 "local@sub.domains.com",
25 "backticks`are`legit@test.com",
26 "digit-only-domain@123.com",
27 "digit-only-domain-with-subdomain@sub.123.com"
28];
29
30const validUnsupported =
31[
32 "\"quoted\"@sld.com",
33 "\"\\e\\s\\c\\a\\p\\e\\d\"@sld.com",
34 "\"quoted-at-sign@sld.org\"@sld.com",
35 "\"escaped\\\"quote\"@sld.com",
36 "\"back\\slash\"@sld.com",
37 "punycode-numbers-in-tld@sld.xn--3e0b707e",
38 "bracketed-IP-instead-of-domain@[127.0.0.1]"
39];
40
41const invalidSupported =
42[
43 "@missing-local.org",
44 "! #$%`|@invalid-characters-in-local.org",
45 "(),:;`|@more-invalid-characters-in-local.org",
46 "<>@[]\\`|@even-more-invalid-characters-in-local.org",
47 ".local-starts-with-dot@sld.com",
48 "local-ends-with-dot.@sld.com",
49 "two..consecutive-dots@sld.com",
50 "partially.\"quoted\"@sld.com",
51 "the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net",
52 "missing-sld@.com",
53 "sld-starts-with-dashsh@-sld.com",
54 "sld-ends-with-dash@sld-.com",
55 "invalid-characters-in-sld@! \"#$%(),/;<>_[]`|.org",
56 "missing-dot-before-tld@com",
57 "missing-tld@sld.",
58 "invalid",
59 "the-total-length@of-an-entire-address.cannot-be-longer-than-two-hundred-and-fifty-four-characters.and-this-address-is-255-characters-exactly.so-it-should-be-invalid.and-im-going-to-add-some-more-words-here.to-increase-the-lenght-blah-blah-blah-blah-bl.org",
60 "the-character-limit@for-each-part.of-the-domain.is-sixty-three-characters.this-is-exactly-sixty-four-characters-so-it-is-invalid-blah-blah.com",
61 "missing-at-sign.net",
62 "unbracketed-IP@127.0.0.1",
63 "invalid-ip@127.0.0.1.26",
64 "another-invalid-ip@127.0.0.256",
65 "IP-and-port@127.0.0.1:25",
66 "trailing-dots@test.de.",
67 "dot-on-dot-in-domainname@te..st.de",
68 "dot-first-in-domain@.test.de",
69 "mg@ns.i"
70];
71describe('TEST EMAILS AGAINST VALIDATOR', () => {
72 it('Should Be Valid', () => {
73 validSupported.forEach( email => {
74 expect(validator.validate(email)).to.equal(true);
75 });
76 });
77
78 it('Should Be Invalid', () => {
79 invalidSupported.forEach( email => {
80 expect(validator.validate(email)).to.equal(false);
81 });
82 });
83
84 it('Should Be Invalid(UnSupported By Module)', () => {
85 validUnsupported.forEach( email => {
86 expect(validator.validate(email)).to.equal(false);
87 });
88 });
89});