function validateProperty(objectForValidate, specificProperty) { return objectForValidate && objectForValidate.hasOwnProperty(specificProperty); }
- function validateProperty(objectForValidate, specificProperty) {
return Boolean(objectForValidate[specificProperty]);- return objectForValidate && objectForValidate.hasOwnProperty(specificProperty);
- }
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 true when the property is equals to empty", function(){ const test = { a: '' }; const validation = validateProperty(test, 'a'); Test.assertEquals(validation, true); }); });
- 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(){- it("should be return true when the property is equals to empty", function(){
- const test = { a: '' };
- const validation = validateProperty(test, 'a');
Test.assertEquals(validation, false);});it("should be return true when the property is equals to zero", function(){const test = { a: '0' };const validation = validateProperty(test, 'a');- Test.assertEquals(validation, true);
- });
it("should be return true when the property is equals to zero", function(){const test = { a: 0 };const validation = validateProperty(test, 'a');Test.assertEquals(validation, false);});it("should be return true when the property is equals to zero", function(){const test = { a: false };const validation = validateProperty(test, 'a');Test.assertEquals(validation, false);});- });