From 37108991acf3413754c6d254ab4a8730ce82f3be Mon Sep 17 00:00:00 2001 From: OleksiiMishchenko Date: Sun, 24 Nov 2024 22:01:53 +0200 Subject: [PATCH] Solution --- src/validateEmail.test.js | 41 ++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/validateEmail.test.js b/src/validateEmail.test.js index 63a3673..545258a 100644 --- a/src/validateEmail.test.js +++ b/src/validateEmail.test.js @@ -3,18 +3,45 @@ describe(`Function 'validateEmail':`, () => { const validateEmail = require('./validateEmail'); - it(`should be declared`, () => { - expect(validateEmail).toBeInstanceOf(Function); - }); + it(`should be declared`, () => expect(validateEmail).toBeDefined()); it(`should return boolean`, () => { - + expect(typeof validateEmail('')).toBe('boolean'); }); it(`should return 'true' for the valid email`, () => { - expect(validateEmail('test838@gmail.com.')) - .toBeTruthy(); + expect(validateEmail('test838@gmail.com')).toBeTruthy(); + }); + + it(`should return 'true' for email name containing digits only`, () => { + expect(validateEmail('838838@gmail.com')).toBeTruthy(); + }); + + it(`should return 'true' for email containing '-', '_' or '.'`, () => { + expect(validateEmail('my.new_e-mail@gmail.com')).toBeTruthy(); + }); + + it(`should return 'false' for email with cyrillic letters`, () => { + expect(validateEmail('моя_пошта@gmail.com')).toBeFalsy(); }); - // write more tests here + it(`should return 'false' for email beginning with '.'`, () => { + expect(validateEmail('.my_e-mail@gmail.com')).toBeFalsy(); + }); + + it(`should return 'false' for domain beginning with '.'`, () => { + expect(validateEmail('my_e-mail@.gmail.com')).toBeFalsy(); + }); + + it(`should return 'false' for email containing not allowed chars`, () => { + const notAllowedChars = `!$%&'*+/=?^{|}~`.split(''); + + notAllowedChars.forEach((char) => { + expect(validateEmail(`my${char}e-mail@gmail.com`)).toBeFalsy(); + }); + }); + + it(`should return 'false' for email without '@'`, () => { + expect(validateEmail('my_e-mail_gmail.com')).toBeFalsy(); + }); });