forked from nmanousos/email-existence
-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.js
91 lines (79 loc) · 2.62 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var emailExistence = require('./index');
var expect = require('expect.js');
describe('emailExistence', function() {
it('is backwards compatible', function() {
expect(emailExistence.check).to.a('function');
});
it('returns false instantly for invalid emails', function(done) {
emailExistence('a@', function(valid, err) {
expect(valid).to.be(false);
done();
});
});
it('allows strange formats but that are technically valid', function(done) {
var ok;
emailExistence('[email protected]', function(valid, err) {
if (!ok) {
throw new Error('should not return immediately');
}
});
ok = true;
done();
});
it('recognizes andreas', function(done) {
this.timeout(30e3);
emailExistence('[email protected]', function(valid, err) {
expect(err).to.match(/^250/);
expect(valid).to.be(true);
done();
});
});
it('recognizes gmail+', function(done) {
this.timeout(30e3);
emailExistence('[email protected]', function(valid, err) {
expect(err).to.match(/^250/);
expect(valid).to.be(true);
done();
});
});
it('fails on unrecognized domain', function(done) {
this.timeout(30e3);
emailExistence('x@doesnotexist', function(valid, err) {
expect(valid).to.be(false);
expect(err.message).to.match(/ENOTFOUND/);
done();
});
});
it('fails on unrecognized domain', function(done) {
this.timeout(30e3);
emailExistence('[email protected]', function(valid, err) {
expect(valid).to.be(false);
expect(err.message).to.match(/ENOTFOUND/);
done();
});
});
it('fails on non-existent address', function(done) {
this.timeout(30e3);
emailExistence('[email protected]', function(valid, err) {
expect(err).to.match(/^550/);
expect(valid).to.be(false);
done();
});
});
it('fails on non-existent name', function(done) {
this.timeout(30e3);
emailExistence('[email protected]', function(valid, err) {
expect(err).to.match(/^550/);
expect(valid).to.be(false);
done();
});
});
it('recognizes valid hotmail', function(done) {
this.timeout(30e3);
emailExistence('[email protected]', function(valid, err) {
expect(err).to.match(/^250/);
expect(valid).to.be(true);
done(err);
});
});
});