1
1
import emailValidator from '../src/index.js' ;
2
2
3
3
describe ( 'Email Validator' , ( ) => {
4
- // Testing with MX record check enabled
5
4
describe ( 'with MX record check' , ( ) => {
6
5
test ( 'should validate correct email format and MX record exists' , async ( ) => {
7
6
expect ( await emailValidator ( '[email protected] ' ) ) . toBe ( true ) ;
@@ -10,9 +9,15 @@ describe('Email Validator', () => {
10
9
test ( 'should reject email from domain without MX records' , async ( ) => {
11
10
expect ( await emailValidator ( '[email protected] ' ) ) . toBe ( false ) ;
12
11
} ) ;
12
+
13
+ test ( 'should reject non-string inputs' , async ( ) => {
14
+ expect ( await emailValidator ( undefined ) ) . toBe ( false ) ;
15
+ expect ( await emailValidator ( null ) ) . toBe ( false ) ;
16
+ expect ( await emailValidator ( 1234 ) ) . toBe ( false ) ;
17
+ expect ( await emailValidator ( { } ) ) . toBe ( false ) ;
18
+ } ) ;
13
19
} ) ;
14
20
15
- // Testing without MX record check
16
21
describe ( 'without MX record check' , ( ) => {
17
22
test ( 'should validate correct email format regardless of MX records' , async ( ) => {
18
23
expect ( await emailValidator ( '[email protected] ' , false ) ) . toBe ( true ) ;
@@ -25,5 +30,12 @@ describe('Email Validator', () => {
25
30
test ( 'should validate email from domain without MX records' , async ( ) => {
26
31
expect ( await emailValidator ( '[email protected] ' , false ) ) . toBe ( true ) ;
27
32
} ) ;
33
+
34
+ test ( 'should reject non-string inputs' , async ( ) => {
35
+ expect ( await emailValidator ( undefined , false ) ) . toBe ( false ) ;
36
+ expect ( await emailValidator ( null , false ) ) . toBe ( false ) ;
37
+ expect ( await emailValidator ( 1234 , false ) ) . toBe ( false ) ;
38
+ expect ( await emailValidator ( { } , false ) ) . toBe ( false ) ;
39
+ } ) ;
28
40
} ) ;
29
41
} ) ;
0 commit comments