Skip to content

Commit 63f49cf

Browse files
committed
better tests
1 parent 0f7fe77 commit 63f49cf

File tree

8 files changed

+4460
-6450
lines changed

8 files changed

+4460
-6450
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,3 @@ Thumbs.db
3737
# Ignore built ts files
3838
dist/**/*
3939

40-
# ignore yarn.lock
41-
yarn.lock

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,31 @@
1212
```
1313
yarn add deep-email-validator
1414
```
15+
16+
```typescript
17+
import validate from 'deep-email-validator'
18+
const main = async () => {
19+
let res = await validate('[email protected]')
20+
// {
21+
// "valid": false,
22+
// "validators": {
23+
// "regex": {
24+
// "valid": true
25+
// },
26+
// "typo": {
27+
// "valid": true
28+
// },
29+
// "disposable": {
30+
// "valid": true
31+
// },
32+
// "mx": {
33+
// "valid": true
34+
// },
35+
// "smtp": {
36+
// "valid": false,
37+
// "reason": "Invalid Mailbox",
38+
// }
39+
// }
40+
// }
41+
}
42+
```

package-lock.json

Lines changed: 0 additions & 6443 deletions
This file was deleted.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "deep-email-validator",
3-
"version": "0.1.2",
3+
"version": "0.1.5",
4+
"files": [
5+
"dist/**/*"
6+
],
47
"description": "Validates emails based on regex, common typos, disposable email blacklists, DNS records and SMTP server response.",
58
"main": "dist/index.js",
69
"types": "dist/index.d.ts",
@@ -36,14 +39,14 @@
3639
"run-debug": "nodemon --inspect dist/server.js"
3740
},
3841
"dependencies": {
39-
"@types/mailcheck": "^1.1.31",
40-
"@types/validator": "^12.0.1",
4142
"axios": "^0.19.2",
4243
"lodash": "^4.17.15",
4344
"mailcheck": "^1.1.1",
4445
"validator": "^12.2.0"
4546
},
4647
"devDependencies": {
48+
"@types/mailcheck": "^1.1.31",
49+
"@types/validator": "^12.0.1",
4750
"@types/eslint": "^6.1.1",
4851
"@types/jest": "^24.0.23",
4952
"@types/lodash": "^4.14.141",

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ async function main() {
3333
}
3434
}
3535
main()
36+
37+
export default validate

test/__snapshots__/index.test.ts.snap

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,32 @@ Object {
144144
},
145145
}
146146
`;
147+
148+
exports[`validation tests passes 1`] = `
149+
Object {
150+
"reason": "smtp",
151+
"valid": false,
152+
"validators": Object {
153+
"disposable": Object {
154+
"reason": undefined,
155+
"valid": true,
156+
},
157+
"mx": Object {
158+
"reason": undefined,
159+
"valid": true,
160+
},
161+
"regex": Object {
162+
"reason": undefined,
163+
"valid": true,
164+
},
165+
"smtp": Object {
166+
"reason": undefined,
167+
"valid": true,
168+
},
169+
"typo": Object {
170+
"reason": undefined,
171+
"valid": true,
172+
},
173+
},
174+
}
175+
`;

test/index.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
import { validate } from '../src/index'
2-
import _ from 'lodash'
32

43
describe('validation tests', () => {
54
it('fails with bad regex', async () => {
65
const res = await validate('dav [email protected]')
76
expect(res).toMatchSnapshot()
87
})
8+
99
it('fails with common typo', async () => {
1010
const res = await validate('[email protected]')
1111
expect(res).toMatchSnapshot()
1212
})
13+
1314
it('fails with disposable email', async () => {
1415
const res = await validate('[email protected]')
1516
expect(res).toMatchSnapshot()
1617
})
1718

1819
it('fails with bad dns', async () => {
19-
const res = await validate('[email protected]')
20+
const res = await validate('[email protected]')
2021
expect(res).toMatchSnapshot()
2122
})
2223

2324
it('fails with bad mailbox', async () => {
2425
const res = await validate('[email protected]')
2526
expect(res).toMatchSnapshot()
2627
})
28+
29+
it('passes', async () => {
30+
const res = await validate('[email protected]')
31+
expect(res).toMatchSnapshot()
32+
})
2733
})

0 commit comments

Comments
 (0)