From e2608e91b5cc33c1da0b7ae321da9ba709c7bf68 Mon Sep 17 00:00:00 2001 From: Mykhailo Date: Sat, 8 Nov 2025 19:28:53 +0100 Subject: [PATCH 1/2] test: add tests for validateEmail function --- src/validateEmail.test.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/validateEmail.test.js b/src/validateEmail.test.js index 63a3673..d76d804 100644 --- a/src/validateEmail.test.js +++ b/src/validateEmail.test.js @@ -8,13 +8,27 @@ describe(`Function 'validateEmail':`, () => { }); it(`should return boolean`, () => { - + expect(typeof validateEmail('test838@gmail.com')).toBe('boolean'); }); it(`should return 'true' for the valid email`, () => { - expect(validateEmail('test838@gmail.com.')) + expect(validateEmail('test838@gmail.com')) .toBeTruthy(); }); - // write more tests here + it(`should return 'false' for email with not allowed char`, () => { + expect(validateEmail('test!838@gmail.com')).toBe(false); + }); + + it(`should return 'false' for email with double dots`, () => { + expect(validateEmail('test..838@gmail.com')).toBe(false); + }); + + it(`should return 'false' if email starts with '.'`, () => { + expect(validateEmail('.test838@gmail.com')).toBe(false); + }); + + it(`should return 'false' for emails without '@'`, () => { + expect(validateEmail('test838gmail.com')).toBe(false); + }); }); From 1ef7a7543409192f89747a0b94aeac049db27802 Mon Sep 17 00:00:00 2001 From: Mykhailo Date: Sat, 8 Nov 2025 19:37:48 +0100 Subject: [PATCH 2/2] test: add more tests for different cases --- src/validateEmail.test.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/validateEmail.test.js b/src/validateEmail.test.js index d76d804..99b9b8a 100644 --- a/src/validateEmail.test.js +++ b/src/validateEmail.test.js @@ -2,6 +2,17 @@ describe(`Function 'validateEmail':`, () => { const validateEmail = require('./validateEmail'); + const cases = [ + { + input: 'test@mail.com', expected: true, + }, + { + input: 't@q.c', expected: true, + }, + { + input: 'test838@gmail.com', expected: true, + }, + ]; it(`should be declared`, () => { expect(validateEmail).toBeInstanceOf(Function); @@ -11,9 +22,10 @@ describe(`Function 'validateEmail':`, () => { expect(typeof validateEmail('test838@gmail.com')).toBe('boolean'); }); - it(`should return 'true' for the valid email`, () => { - expect(validateEmail('test838@gmail.com')) - .toBeTruthy(); + it(`should return 'true' for all valid emails`, () => { + cases.forEach(({ input, expected }) => { + expect(validateEmail(input)).toBe(expected); + }); }); it(`should return 'false' for email with not allowed char`, () => { @@ -31,4 +43,16 @@ describe(`Function 'validateEmail':`, () => { it(`should return 'false' for emails without '@'`, () => { expect(validateEmail('test838gmail.com')).toBe(false); }); + + it(`should return 'false' for email without dot in domain part`, () => { + expect(validateEmail('false@email')).toBe(false); + }); + + it(`should return 'false' if '.' is directly before '@'`, () => { + expect(validateEmail('false.@email.com')).toBe(false); + }); + + it(`should return 'false' if '.' is directly after '@'`, () => { + expect(validateEmail('false@.email.com')).toBe(false); + }); });