-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide tests for `validateEmail`, `validatePhoneNumber`, `validateForgotUsernameForm`.
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import validateEmail from './validateEmail'; | ||
|
||
describe('validateEmail', () => { | ||
it('accepts valid email addresses', () => { | ||
expect(validateEmail('test@example.edu')).toBe(true); | ||
}); | ||
|
||
it('accepts values with comments in username', () => { | ||
expect(validateEmail('test+comment@example.edu')).toBe(true); | ||
}); | ||
|
||
it('rejects values without @', () => { | ||
expect(validateEmail('test$example.edu')).toBe(false); | ||
}); | ||
|
||
it('rejects values without domain suffix', () => { | ||
expect(validateEmail('test@example')).toBe(false); | ||
}); | ||
|
||
it('rejects values with whitespace', () => { | ||
expect(validateEmail(' test@example.com ')).toBe(false); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
src/validators/validateForgotUsernameForm/validateForgotUsernameForm.test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import validateForgotUsernameForm from './validateForgotUsernameForm'; | ||
|
||
describe('validateForgotUsernameForm', () => { | ||
describe('accepts valid email addresses and phone numbers', () => { | ||
it('accepts valid email addresses', () => { | ||
expect(validateForgotUsernameForm('test@example.edu')).toBe(true); | ||
}); | ||
|
||
it('accepts values with comments in username', () => { | ||
expect(validateForgotUsernameForm('test+comment@example.edu')).toBe(true); | ||
}); | ||
|
||
it('accepts values with numbers only', () => { | ||
expect(validateForgotUsernameForm('12')).toBe(true); | ||
}); | ||
|
||
it('accepts values with numbers and dashes', () => { | ||
expect(validateForgotUsernameForm('1-2')).toBe(true); | ||
}); | ||
|
||
it('accepts values with numbers and dots', () => { | ||
expect(validateForgotUsernameForm('1.2')).toBe(true); | ||
}); | ||
}); | ||
|
||
it('rejects values that are not valid email addresses or phone numbers', () => { | ||
// validateForgotUsernameForm trims whitespace so we don't test for | ||
// whitespace rejection here, even though other validators do. | ||
expect(validateForgotUsernameForm('not an email address')).toBe(false); | ||
expect(validateForgotUsernameForm('not a phone number')).toBe(false); | ||
expect(validateForgotUsernameForm('test$example.edu')).toBe(false); | ||
expect(validateForgotUsernameForm('test@example')).toBe(false); | ||
expect(validateForgotUsernameForm('1.2a')).toBe(false); | ||
expect(validateForgotUsernameForm('1.2!')).toBe(false); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/validators/validatePhoneNumber/validatePhoneNumber.test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import validatePhoneNumber from './validatePhoneNumber'; | ||
|
||
describe('validatePhoneNumber', () => { | ||
it('accepts values with numbers only', () => { | ||
expect(validatePhoneNumber('12')).toBe(true); | ||
}); | ||
|
||
it('accepts values with numbers and dashes', () => { | ||
expect(validatePhoneNumber('1-2')).toBe(true); | ||
}); | ||
|
||
it('accepts values with numbers and dots', () => { | ||
expect(validatePhoneNumber('1.2')).toBe(true); | ||
}); | ||
|
||
it('rejects values containing characters other than numbers, dashes, and dots', () => { | ||
expect(validatePhoneNumber('1.2 ')).toBe(false); | ||
expect(validatePhoneNumber('1.2a')).toBe(false); | ||
expect(validatePhoneNumber('1.2!')).toBe(false); | ||
}); | ||
}); | ||
|