Created
August 13, 2017 18:45
-
-
Save erika-dike/fe02b78d1a589b21f7aad2e8fc628dba to your computer and use it in GitHub Desktop.
This file contains hidden or 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('replaceUrlsWithLinks test suite', () => { | |
| it('replaces single url with anchor links', () => { | |
| const text = 'Search http://google.com'; | |
| const url = ['http://google.com']; | |
| const expected = `Search <a href=${url}>${url}</a>`; | |
| expect(replaceUrlsWithLinks(text, url)).toEqual(expected); | |
| }); | |
| it('replaces multiple urls in a text with anchor links', () => { | |
| const text = [ | |
| 'I search with http://google.com,', | |
| 'watch videos on http://youtube.com and catch up with friends on', | |
| 'http://facebook.com', | |
| ].join(' '); | |
| const urls = [ | |
| 'http://google.com', 'http://youtube.com', 'http://facebook.com', | |
| ]; | |
| const expected = [ | |
| `I search with <a href=${urls[0]}>${urls[0]}</a>,`, | |
| `watch videos on <a href=${urls[1]}>${urls[1]}</a>`, | |
| 'and catch up with friends on', | |
| `<a href=${urls[2]}>${urls[2]}</a>`, | |
| ].join(' '); | |
| expect(replaceUrlsWithLinks(text, urls)).toEqual(expected); | |
| }); | |
| it('returns unmodified text when no url', () => { | |
| const text = "What do you do when the url param is empty"; | |
| const url = []; | |
| expect(replaceUrlsWithLinks(text, url)).toEqual(text); | |
| }); | |
| it('returns empty string when empty text is passed', () => { | |
| const text = ''; | |
| const url = ['http://google.com']; | |
| expect(replaceUrlsWithLinks(text, url)).toEqual(text); | |
| }); | |
| it('returns empty string when both text and url is empty', () => { | |
| expect(replaceUrlsWithLinks('', [])).toEqual(''); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment