-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrawl.test.js
17 lines (15 loc) · 1.17 KB
/
crawl.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { test, expect } from "@jest/globals";
import { normalizeURL, getURLsFromHTML } from "./crawl.js";
test('normalize http://example.com/ to example.com', () => {
expect(normalizeURL('http://example.com/')).toBe('example.com');
expect(normalizeURL('https://example.com/')).toBe('example.com');
expect(normalizeURL('http://example.com')).toBe('example.com');
expect(normalizeURL('https://example.com')).toBe('example.com');
expect(normalizeURL('example.com')).toBe('example.com');
expect(normalizeURL('example.com/')).toBe('example.com');
});
test('Get links from anchor tags in html', () => {
expect(getURLsFromHTML('<a href="https://boot.dev">Learn Backend Development</a>', 'https://boot.dev')).toStrictEqual(['https://boot.dev']);
expect(getURLsFromHTML('<html><body><a href="https://blog.boot.dev"><span>Go to Boot.dev</span></a></body></html>', 'https://boot.dev')).toStrictEqual(['https://blog.boot.dev']);
expect(getURLsFromHTML('<html><body><a href="https://blog.boot.dev"><span>Go to Boot.dev</span></a><a href="/post1"></a></body></html>', 'https://blog.boot.dev')).toStrictEqual(['https://blog.boot.dev', 'https://blog.boot.dev/post1']);
});