Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions src/validateEmail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,57 @@

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);
});

it(`should return boolean`, () => {
expect(typeof validateEmail('test838@gmail.com')).toBe('boolean');
});

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`, () => {
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);
});

it(`should return 'true' for the valid email`, () => {
expect(validateEmail('test838@gmail.com.'))
.toBeTruthy();
it(`should return 'false' for email without dot in domain part`, () => {
expect(validateEmail('false@email')).toBe(false);
});

// write more tests here
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);
});
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test suite is missing several required cases. You should add tests for all the examples from the description (like 'test@mail.com', 't@q.c', and 'false@email'). Also, consider adding tests for other rules, such as a dot not being allowed immediately before the @ or at the start of the domain.