|
1 | 1 | import { validate } from '../src/index'
|
2 | 2 |
|
| 3 | +const elevenSeconds = 11 * 1000 |
| 4 | + |
3 | 5 | describe('validation tests', () => {
|
4 | 6 | it('fails with bad regex', async () => {
|
5 | 7 | 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 | + |
| 15 | + validateRegex: false, |
| 16 | + }) |
| 17 | + expect(res.valid).toBe(false) |
6 | 18 | expect(res).toMatchSnapshot()
|
7 | 19 | })
|
8 | 20 |
|
9 | 21 | it('fails with common typo', async () => {
|
10 | 22 | const res = await validate('[email protected]')
|
| 23 | + expect(res.valid).toBe(false) |
11 | 24 | expect(res).toMatchSnapshot()
|
12 | 25 | })
|
13 | 26 |
|
14 | 27 | it('fails with disposable email', async () => {
|
15 | 28 | const res = await validate('[email protected]')
|
| 29 | + expect(res.valid).toBe(false) |
16 | 30 | expect(res).toMatchSnapshot()
|
17 | 31 | })
|
18 | 32 |
|
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 | + ) |
23 | 42 |
|
24 | 43 | it('fails with bad mailbox', async () => {
|
25 | 44 | const res = await validate('[email protected]')
|
| 45 | + expect(res.valid).toBe(false) |
26 | 46 | expect(res).toMatchSnapshot()
|
27 | 47 | })
|
28 | 48 |
|
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 | + ) |
33 | 58 |
|
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 | + }) |
38 | 66 |
|
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 | + ) |
43 | 91 | })
|
0 commit comments