Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* eslint-env jasmine */
- import { validate, suggest } from './email';
- describe('email', () => {
- describe('validate', () => {
- it('should correctly validate correct email addresses', (done) => {
- const promises = [
- validate('user@gmail.com'),
- validate('user+dix@host.ca'),
- validate('user+dix@sub.domain.tld'),
- validate('gianni@butt.zone')
- ];
- Promise.all(promises).then(done, done.fail);
- });
- it('should correctly validate incorrect email addresses', (done) => {
- const promises = [
- validate('@').then(() => { throw 'fail'; }, () => true),
- validate('user name@domain.com').then(() => { throw 'fail'; }, () => true),
- validate('user@domain lol.com').then(() => { throw 'fail'; }, () => true),
- validate('user@domain.c om').then(() => { throw 'fail'; }, () => true),
- validate('gmail.com').then(() => { throw 'fail'; }, () => true),
- validate('@gmail.com').then(() => { throw 'fail'; }, () => true),
- validate('user@gmail.').then(() => { throw 'fail'; }, () => true),
- validate('user@.com').then(() => { throw 'fail'; }, () => true)
- ];
- Promise.all(promises).then(done, done.fail);
- });
- it('should correctly validate an email address with unicode characters', (done) => {
- validate('snædis@💩.com').then(done, done.fail);
- });
- });
- describe('suggest', () => {
- it('should not suggest correct domains & tlds', (done) => {
- const promises = [
- suggest('user@gmail.com').then(e => { throw `fail: ${e}`; }, () => true),
- suggest('user@hotmail.co.uk').then(e => { throw `fail: ${e}`; }, () => true)
- ];
- Promise.all(promises).then(done, done.fail);
- });
- it('should not suggest correct but unknown domains & tlds', (done) => {
- const promises = [
- suggest('user@universe.com').then(e => { throw `fail: ${e}`; }, () => true)
- ];
- Promise.all(promises).then(done, done.fail);
- });
- it('should not suggest emails that are too far gone', (done) => {
- const promises = [
- suggest('user@gmaillolobuzz').then(e => { throw `fail: ${e}`; }, () => true),
- suggest('user@mailhotmail.co.uk.mailhotmail').then(e => { throw `fail: ${e}`; }, () => true)
- ];
- Promise.all(promises).then(done, done.fail);
- });
- it('should suggest misspelled domains', (done) => {
- const promises = [
- suggest('user@gnail.com').then(e => expect(e).toEqual('user@gmail.com'), () => { throw 'fail: user@gnail.com'; }),
- suggest('user@hotmale.co.uk').then(e => expect(e).toEqual('user@hotmail.co.uk'), () => { throw 'fail: user@hotmale.co.uk'; })
- ];
- Promise.all(promises).then(done, done.fail);
- });
- it('should suggest misspelled TLDs', (done) => {
- const promises = [
- suggest('user@gmail.cmo').then(e => expect(e).toEqual('user@gmail.com'), () => { throw 'fail: user@gmail.cmo'; }),
- suggest('user@gmail.cm').then(e => expect(e).toEqual('user@gmail.com'), () => { throw 'fail: user@gmail.cm'; }),
- suggest('user@hotmail.ci.uk').then(e => expect(e).toEqual('user@hotmail.co.uk'), () => { throw 'fail: user@hotmail.ci.uk'; }),
- suggest('user@hotmail.couk').then(e => expect(e).toEqual('user@hotmail.co.uk'), () => { throw 'fail: user@hotmail.couk'; })
- ];
- Promise.all(promises).then(done, done.fail);
- });
- it('should suggest misspelled TLDs for unknown domains', (done) => {
- const promises = [
- suggest('gianni@universe.cmo').then(e => expect(e).toEqual('gianni@universe.com'), () => { throw 'fail: gianni@universe.cmo'; }),
- suggest('gianni@universecom').then(e => expect(e).toEqual('gianni@universe.com'), () => { throw 'fail: gianni@universecom'; })
- ];
- Promise.all(promises).then(done, done.fail);
- });
- it('should suggest misspelled domains and TLDs', (done) => {
- const promises = [
- suggest('user@gmailcom').then(e => expect(e).toEqual('user@gmail.com'), () => { throw 'fail: user@gmailcom'; }),
- suggest('user@gnailcon').then(e => expect(e).toEqual('user@gmail.com'), () => { throw 'fail: user@gnailcon'; }),
- suggest('user@hotmailco.uk').then(e => expect(e).toEqual('user@hotmail.co.uk'), () => { throw 'fail: user@hotmailco.uk'; })
- ];
- Promise.all(promises).then(done, done.fail);
- });
- });
- });
Add Comment
Please, Sign In to add comment