Last active
January 7, 2016 16:52
-
-
Save edysegura/159b853647a5e475b1ce to your computer and use it in GitHub Desktop.
[JS] Example of Automated Test with Jasmine
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
describe('MathService',function(){ | |
it('should sum two integer numbers', function(){ | |
expect(MathService.add(1,2)).toBe(3); | |
}); | |
it('should sum one number or more', function() { | |
expect(MathService.add(1)).toBe(1); | |
expect(MathService.add(1,2)).toBe(3); | |
expect(MathService.add(1,2,3)).toBe(6); | |
}); | |
it('should sum two string numbers', function() { | |
expect(MathService.add('1','2')).toBe(3); | |
expect(MathService.add('010','2')).toBe(12); | |
}); | |
it('should return null for a invalid number', function () { | |
expect(MathService.add('little potato',2)).toBe(null); | |
}); | |
it('should return null if there is no numbers specified', function (){ | |
expect(MathService.add('','')).toBe(null); | |
}); | |
}); |
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
var MathService = { | |
add: function() { | |
var amount = arguments.length; | |
var total = 0; | |
if(amount > 0) { | |
for(var i=0; i<amount; i++) { | |
var currentNumber = parseInt(arguments[i], 10); | |
if(isNaN(currentNumber)) return null; | |
total += currentNumber; | |
} | |
return total; | |
} | |
return null; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment