Last active
December 25, 2015 17:49
-
-
Save scvnc/7016129 to your computer and use it in GitHub Desktop.
"It should have a working LoginService" is way to broad for a single test in my opinion. I think they should be broken out into individual tests so that when the tests fail you know exactly why. Referring to the unit test example in http://andyshora.com/unit-testing-best-practices-angularjs.html
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
// http://andyshora.com/unit-testing-best-practices-angularjs.html | |
// "It should have a working LoginService" is way to broad for a single behavior test in my opinion. | |
// I think they should be broken out into individual tests so that when the tests fail you know exactly why. | |
// CODE IS UNTESTED, only sketched out. It can be done this way. | |
describe('LoginService', function(){ | |
describe('email validator', function(){ | |
// The function which assembles a state that the email validator should be tested against. | |
var testEmail = function(email, isValid){ | |
// @param email: the email that represents the state the validator should be tested against | |
// @param isValid: the expected behavior of the validator given the state. | |
describe('when validating ' + email , function () { | |
var result; | |
beforeEach(function () { | |
result = LoginService.isValidEmail(email); | |
}); | |
it('should return ' + isValid? 'true' : 'false' , function () { | |
expect(result).toBe(isValid); | |
}); | |
}); | |
// It will read ' when validating email@example.com, it should return true' | |
}; | |
// Begin testing behaviors of various states as written in the article. | |
// test cases - testing for success | |
var validEmails = [ | |
'test@test.com', | |
'test@test.co.uk', | |
'test734ltylytkliytkryety9ef@jb-fe.com' | |
]; | |
// test cases - testing for failure | |
var invalidEmails = [ | |
'test@testcom', | |
'test@ test.co.uk', | |
'ghgf@fe.com.co.', | |
'tes*t@test.com' | |
]; | |
// you can loop through arrays of test cases like this | |
for (var i in validEmails) { | |
testEmail(validEmails[i], true); | |
} | |
for (var i in invalidEmails) { | |
testEmail(invalidEmails[i], false); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment