Last active
March 21, 2019 10:08
-
-
Save imdadul/832e102acd0ebef9d9633653b4d5326e to your computer and use it in GitHub Desktop.
Writing test for all functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param firstName | |
* @param lastName | |
* @param address | |
* @constructor | |
*/ | |
function Person(firstName, lastName, address) { | |
let self = this; | |
this.firstName = firstName; | |
this.lastName = lastName; | |
this.address = address; | |
/** | |
* @return {string} | |
*/ | |
this.getAddress = function() { | |
return _.get(self.address, ['city']) + '(' + _.get(self.address, ['country']) + ')'; | |
} | |
/** | |
* @return {string} | |
*/ | |
this.getFullName = function() { | |
return self.firstName + ' ' + self.lastName; | |
} | |
/** | |
* @return {string} | |
*/ | |
this.getInfo = function() { | |
return 'His name is ' + self.getFullName() + ' and lives in ' + self.getAddress(); | |
}; | |
} | |
// Person.spec.js | |
describe('Testing Person ', function() { | |
var person; | |
beforeEach(function() { | |
person = new Person('Imdadul', 'Huq', { country: 'Germany', city: 'Darmstadt' }); | |
}) | |
describe('Test of getInfo', function() { | |
beforeEach(function() { | |
spyOn(person, 'getFullName').and.callFake(function() { | |
return 'abraka-dabra'; | |
}); | |
spyOn(person, 'getAddress').and.callFake(function() { | |
return 'no-where'; | |
}); | |
}); | |
expect(person.getInfo()).toEqual('His name is abraka-dabra and lives in no-where'); | |
}); | |
describe('Test of getFullName', function() { | |
expect(person.getFullName()).toEqual('Imdadul Huq'); | |
}); | |
describe('Test of getFullName', function() { | |
expect(person.getAddress()).toEqual('Darmstadt(Germany)'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment