-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds tests for isValid url validation method
- Loading branch information
1 parent
c2452a8
commit a1bef19
Showing
2 changed files
with
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,3 +91,4 @@ SafeLink.tagName = 'A'; | |
|
||
|
||
export { SafeLink as default }; | ||
export { isValid }; |
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,49 @@ | ||
import { isValid } from './link'; | ||
|
||
describe('SafeLink', () => { | ||
describe('isValid', () => { | ||
test('allows anchor links', () => { | ||
expect(isValid('#anchor-link')).toEqual(true); | ||
}); | ||
|
||
test('allows links relative to the site root', () => { | ||
expect(isValid('/section')).toEqual(true); | ||
}); | ||
|
||
test('allows mailto links', () => { | ||
expect(isValid('mailto:[email protected]')).toEqual(true); | ||
}); | ||
|
||
test('allows ftp links', () => { | ||
expect(isValid('ftp://example.com/file')).toEqual(true); | ||
}); | ||
|
||
test('allows http links', () => { | ||
expect(isValid('http://example.com/foo')).toEqual(true); | ||
}); | ||
|
||
test('allows https links', () => { | ||
expect(isValid('https://example.com/foo')).toEqual(true); | ||
}); | ||
|
||
test('allows links without path', () => { | ||
expect(isValid('https://example.com')).toEqual(true); | ||
}); | ||
|
||
test('rejects anchor links with spaces', () => { | ||
expect(isValid('#anchor link')).toEqual(false); | ||
}); | ||
|
||
test('rejects links relative to current page', () => { | ||
expect(isValid('section')).toEqual(false); | ||
}); | ||
|
||
test('rejects mailto links without @', () => { | ||
expect(isValid('mailto:example')).toEqual(false); | ||
}); | ||
|
||
test('rejects links without a protocol', () => { | ||
expect(isValid('example.com/foo')).toEqual(false); | ||
}); | ||
}); | ||
}); |