Skip to content

Commit 76a69d5

Browse files
committed
update tests
1 parent 32d8872 commit 76a69d5

File tree

2 files changed

+114
-18
lines changed

2 files changed

+114
-18
lines changed

test/__snapshots__/index.test.ts.snap

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`validation tests fails later with malformed regex 1`] = `
4+
Object {
5+
"reason": "smtp",
6+
"valid": false,
7+
"validators": Object {
8+
"disposable": Object {
9+
"valid": true,
10+
},
11+
"mx": Object {
12+
"valid": true,
13+
},
14+
"regex": Object {
15+
"valid": true,
16+
},
17+
"smtp": Object {
18+
"reason": "The mail address that you specified was not syntactically correct.",
19+
"valid": true,
20+
},
21+
"typo": Object {
22+
"valid": true,
23+
},
24+
},
25+
}
26+
`;
27+
328
exports[`validation tests fails with bad dns 1`] = `
429
Object {
530
"reason": "mx",
@@ -150,7 +175,30 @@ Object {
150175
}
151176
`;
152177

153-
exports[`validation tests passes 1`] = `
178+
exports[`validation tests passes when valid special char 1`] = `
179+
Object {
180+
"valid": true,
181+
"validators": Object {
182+
"disposable": Object {
183+
"valid": true,
184+
},
185+
"mx": Object {
186+
"valid": true,
187+
},
188+
"regex": Object {
189+
"valid": true,
190+
},
191+
"smtp": Object {
192+
"valid": true,
193+
},
194+
"typo": Object {
195+
"valid": true,
196+
},
197+
},
198+
}
199+
`;
200+
201+
exports[`validation tests passes when valid wildcard 1`] = `
154202
Object {
155203
"valid": true,
156204
"validators": Object {
@@ -173,7 +221,7 @@ Object {
173221
}
174222
`;
175223

176-
exports[`validation tests passes 2`] = `
224+
exports[`validation tests passes when we skip smtp validation 1`] = `
177225
Object {
178226
"valid": true,
179227
"validators": Object {

test/index.test.ts

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,91 @@
11
import { validate } from '../src/index'
22

3+
const elevenSeconds = 11 * 1000
4+
35
describe('validation tests', () => {
46
it('fails with bad regex', async () => {
57
const res = await validate('dav [email protected]')
8+
expect(res.valid).toBe(false)
9+
expect(res).toMatchSnapshot()
10+
})
11+
12+
it('fails later with malformed regex', async () => {
13+
const res = await validate({
14+
email: 'dav [email protected]',
15+
validateRegex: false,
16+
})
17+
expect(res.valid).toBe(false)
618
expect(res).toMatchSnapshot()
719
})
820

921
it('fails with common typo', async () => {
1022
const res = await validate('[email protected]')
23+
expect(res.valid).toBe(false)
1124
expect(res).toMatchSnapshot()
1225
})
1326

1427
it('fails with disposable email', async () => {
1528
const res = await validate('[email protected]')
29+
expect(res.valid).toBe(false)
1630
expect(res).toMatchSnapshot()
1731
})
1832

19-
it('fails with bad dns', async () => {
20-
const res = await validate('[email protected]')
21-
expect(res).toMatchSnapshot()
22-
})
33+
it(
34+
'fails with bad dns',
35+
async () => {
36+
const res = await validate('[email protected]')
37+
expect(res.valid).toBe(false)
38+
expect(res).toMatchSnapshot()
39+
},
40+
elevenSeconds
41+
)
2342

2443
it('fails with bad mailbox', async () => {
2544
const res = await validate('[email protected]')
45+
expect(res.valid).toBe(false)
2646
expect(res).toMatchSnapshot()
2747
})
2848

29-
it('fails with bad mailbox', async () => {
30-
const res = await validate('[email protected]')
31-
expect(res).toMatchSnapshot()
32-
})
49+
it(
50+
'fails with bad mailbox',
51+
async () => {
52+
const res = await validate('[email protected]')
53+
expect(res.valid).toBe(false)
54+
expect(res).toMatchSnapshot()
55+
},
56+
elevenSeconds
57+
)
3358

34-
it('passes', async () => {
35-
const res = await validate('[email protected]')
36-
expect(res).toMatchSnapshot()
37-
})
59+
it(
60+
'passes when we skip smtp validation',
61+
async () => {
62+
const res = await validate({
63+
64+
validateSMTP: false,
65+
})
3866

39-
it('passes', async () => {
40-
const res = await validate('[email protected]')
41-
expect(res).toMatchSnapshot()
42-
})
67+
expect(res).toMatchSnapshot()
68+
},
69+
elevenSeconds
70+
)
71+
72+
it(
73+
'passes when valid special char',
74+
async () => {
75+
const res = await validate('[email protected]')
76+
expect(res.valid).toBe(true)
77+
expect(res).toMatchSnapshot()
78+
},
79+
elevenSeconds
80+
)
81+
82+
it(
83+
'passes when valid wildcard',
84+
async () => {
85+
const res = await validate('[email protected]')
86+
expect(res.valid).toBe(true)
87+
expect(res).toMatchSnapshot()
88+
},
89+
elevenSeconds
90+
)
4391
})

0 commit comments

Comments
 (0)