const parse = (value = '') => {
if (/^[^@]+@[^@]+\.[a-zA-Z]{2,}$/.test(value)) {
return true
} else {
return false
}
}
describe("Solution", function() {
it("Debe pasar con Yjimenezar001@gmail.com", function() {
const email1 = "Yjimenezar001@gmail.com";
Test.assertEquals(true, parse(email1));
});
it("Debe fallar con Yjimenezar001@gmail.com with white space", function() {
const email1 = "Yjimenezar001@gmail.com ";
Test.assertEquals(false, parse(email1));
});
});
function replaceAllInTextWith(text, search, textReplace) {
return text.split(search).join(textReplace)
}
describe("Solution", function() {
it("Debe limpiar los espacios en blanco", function() {
const emailWithWithSpace = "Yjimenezar001@gmail.com ";
const other = "Y jimene zar001@gmail.com ";
Test.assertEquals("Yjimenezar001@gmail.com", replaceAllInTextWith(emailWithWithSpace, ' ', ''));
Test.assertEquals("Yjimenezar001@gmail.com", replaceAllInTextWith(other, ' ', ''));
});
});
Validate a property in object
function validateProperty(objectForValidate, specificProperty) {
if(objectForValidate[specificProperty]){
return true;
} else{
return false;
}
}
describe("Validate property in object", function(){
it("should be return true when the property exists", function(){
const test = { a: 2 };
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, true);
});
it("should be return false when the property not exists", function(){
const test = {};
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);
});
it("should be return false when the property is equals to empty", function(){
const test = { a: '' };
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);
});
});
Validate a porperty in object
function validateProperty(objectForValidate, specificProperty) {
if(objectForValidate[specificProperty]){
return true;
} else{
return false;
}
}
describe("Validate property in object", function(){
it("should be return true when the property exists", function(){
const test = { a: 2 };
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, true);
});
it("should be return false when the property not exists", function(){
const test = {};
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);
});
it("should be return false when the property is equals to empty", function(){
const test = { a: '' };
const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);
});
});