-
Notifications
You must be signed in to change notification settings - Fork 1
/
links-finder.spec.js
45 lines (36 loc) · 1.61 KB
/
links-finder.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import linksFinder from './../index';
describe('links-finder', () => {
it('should return empty array for empty string', () => {
expect(linksFinder.findLinks('')).toEqual([]);
});
it('should return empty array for empty string', () => {
expect(linksFinder.findLinks('magic')).toEqual([]);
});
it('should return link coordinates', () => {
expect(linksFinder.findLinks('magic http://blah.com another')).toEqual([{start: 6, end: 20}]);
});
it('should return links coordinates', () => {
expect(linksFinder.findLinks('magic http://blah.com and https://x.com')).toEqual([{start: 6, end: 20}, {start: 26, end: 38}]);
});
it('should return links without http', () => {
expect(linksFinder.findLinks('magic www.blah.com and some')).toEqual([{start: 6, end: 17}]);
});
it('should return link without http and without www', () => {
expect(linksFinder.findLinks('magic blah.com')).toEqual([{start: 6, end: 13}]);
});
it('should wrap link with <a>', () => {
expect(linksFinder.wrapLinks('magic http://blah.com', {
onMatch: (link) => `<a href="${link}">${link}</a>`
})).toBe('magic <a href=\"http://blah.com\">http://blah.com</a>')
});
it('should wrap links with <a>', () => {
expect(linksFinder.wrapLinks('magic http://blah.com and https://x.com', {
onMatch: (link) => `<a href="${link}">${link}</a>`
})).toBe('magic <a href=\"http://blah.com\">http://blah.com</a> and <a href=\"https://x.com\">https://x.com</a>');
});
it('should remove links', () => {
expect(linksFinder.wrapLinks('magic http://blah.com', {
onMatch: () => ''
})).toBe('magic ');
});
});