Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #114

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
41 changes: 34 additions & 7 deletions src/validateEmail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected].'))
.toBeTruthy();
expect(validateEmail('[email protected]')).toBeTruthy();
});

it(`should return 'true' for email name containing digits only`, () => {
expect(validateEmail('[email protected]')).toBeTruthy();
});

it(`should return 'true' for email containing '-', '_' or '.'`, () => {
expect(validateEmail('[email protected]')).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('[email protected]')).toBeFalsy();
});

it(`should return 'false' for domain beginning with '.'`, () => {
expect(validateEmail('[email protected]')).toBeFalsy();
});

it(`should return 'false' for email containing not allowed chars`, () => {
const notAllowedChars = `!$%&'*+/=?^{|}~`.split('');

notAllowedChars.forEach((char) => {
expect(validateEmail(`my${char}[email protected]`)).toBeFalsy();
});
});

it(`should return 'false' for email without '@'`, () => {
expect(validateEmail('my_e-mail_gmail.com')).toBeFalsy();
});
});