File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ function that takes a string input and return either it is true of false
3+ a valid email address
4+ e.g.: mahfoudh.arous@gmail.com -> true
5+ e.g.: mahfoudh.arous.com ->false
6+ */
7+
8+ const validateEmail = ( str ) => {
9+ if ( str === '' || str === null ) {
10+ throw new TypeError ( 'Email Address String Null or Empty.' )
11+ }
12+ if ( str . startsWith ( '@' ) === true || ! str . includes ( '@' ) || ! str . endsWith ( '.com' ) ) {
13+ return false
14+ }
15+
16+ return true
17+ }
18+
19+ export { validateEmail }
Original file line number Diff line number Diff line change 1+ import { validateEmail } from './ValidateEmail'
2+
3+ describe ( 'Validation of an Email Address' , ( ) => {
4+ it ( 'expects to return false' , ( ) => {
5+ expect ( validateEmail ( 'mahfoudh.arous.com' ) ) . toEqual ( false )
6+ } )
7+
8+ it ( 'expects to return false' , ( ) => {
9+ expect ( validateEmail ( 'mahfoudh.arous@com' ) ) . toEqual ( false )
10+ } )
11+
12+ it ( 'expects to return true' , ( ) => {
13+ expect ( validateEmail ( 'mahfoudh.arous@gmail.com' ) ) . toEqual ( true )
14+ } )
15+
16+ it ( 'expects to throw a type error' , ( ) => {
17+ expect ( ( ) => { validateEmail ( '' ) } ) . toThrow ( 'Email Address String Null or Empty.' )
18+ } )
19+ } )
You can’t perform that action at this time.
0 commit comments