Skip to content

Commit

Permalink
Rewrite tests with mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
manishsaraan committed Apr 7, 2018
1 parent ea8c368 commit 04743b3
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
email-validator.sublime-project
email-validator.sublime-workspace
node_modules
248 changes: 248 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"author": "Robert Schultz <robert@cosmicrealms.com>",
"description": "Provides a fast, pretty robust e-mail validator. Only checks form, not function.",
"main": "index",
"scripts" : {
"test" : "mocha test.js"
},
"typings": "index.d.ts",
"engines": {
"node": ">0.3.0"
Expand Down Expand Up @@ -31,5 +34,9 @@
"repository": {
"type": "git",
"url": "http://github.com/Sembiance/email-validator.git"
},
"devDependencies": {
"chai": "4.1.2",
"mocha": "5.0.5"
}
}
44 changes: 22 additions & 22 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"use strict";
const expect = require('chai').expect;
const validator = require(".");

var validator = require("./index");

var validSupported =
const validSupported =
[
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org",
"01234567890@numbers-in-local.net",
Expand All @@ -28,7 +27,7 @@ var validSupported =
"digit-only-domain-with-subdomain@sub.123.com"
];

var validUnsupported =
const validUnsupported =
[
"\"quoted\"@sld.com",
"\"\\e\\s\\c\\a\\p\\e\\d\"@sld.com",
Expand All @@ -39,7 +38,7 @@ var validUnsupported =
"bracketed-IP-instead-of-domain@[127.0.0.1]"
];

var invalidSupported =
const invalidSupported =
[
"@missing-local.org",
"! #$%`|@invalid-characters-in-local.org",
Expand Down Expand Up @@ -69,21 +68,22 @@ var invalidSupported =
"dot-first-in-domain@.test.de",
"mg@ns.i"
];
describe('TEST EMAILS AGAINST VALIDATOR', () => {
it('Should Be Valid', () => {
validSupported.forEach( email => {
expect(validator.validate(email)).to.equal(true);
});
});

console.log('SYNC VERSION TESTS')
console.log('=====================')
console.log("SUPPORTED BY MODULE:\n");

console.log("SHOULD BE VALID:");
validSupported.forEach(function(email) { console.log("%s : %s", validator.validate(email) ? " VALID" : " INVALID", email); });

console.log("\nSHOULD BE INVALID:");
invalidSupported.forEach(function(email) { console.log("%s : %s", validator.validate(email) ? " VALID" : " INVALID", email); });

console.log("\n\nNOT SUPPORTED BY MODULE:\n");

console.log("SHOULD BE VALID:");
validUnsupported.forEach(function(email) { console.log("%s : %s", validator.validate(email) ? " VALID" : " INVALID", email); });

it('Should Be Invalid', () => {
invalidSupported.forEach( email => {
expect(validator.validate(email)).to.equal(false);
});
});

process.exit(0);
it('Should Be Invalid(UnSupported By Module)', () => {
validUnsupported.forEach( email => {
expect(validator.validate(email)).to.equal(false);
});
});
});

0 comments on commit 04743b3

Please sign in to comment.