-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.spec.js
More file actions
44 lines (39 loc) · 1.41 KB
/
index.spec.js
File metadata and controls
44 lines (39 loc) · 1.41 KB
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
import { describe, it, expect } from 'vitest';
import { createHar } from './index.js';
describe('createHar', () => {
it('rejects when no URL', async () => {
await expect(createHar()).rejects.toThrow(/expected string/);
});
it('rejects when URL not a string', async () => {
await expect(createHar(new Date())).rejects.toThrow(/expected string/);
});
it('rejects when page fails to load', async () => {
const url = 'https://example.com/';
await expect(createHar(url, {
routes: {
[url]: request => request.abort(),
},
})).rejects.toThrow(/net::ERR_FAILED/);
});
it('resolves with har object', async () => {
const url = 'https://example.com/';
const html = '<html><body><a href="https://example.com">Example</a></body></html>';
const result = await createHar(url, {
routes: {
[url]: {
status: 200,
contentType: 'text/html',
body: html,
},
},
});
expect(result.log.version).toBe('1.2');
expect(result.log.pages.length).toBe(1);
expect(result.log.pages[0].pageTimings.onContentLoad).toBeGreaterThan(0);
expect(result.log.pages[0].pageTimings.onLoad).toBeGreaterThan(0);
expect(result.log.pages[0]._url).toBe(url);
expect(result.log.pages[0]._links.length).toBe(1);
expect(result.log.pages[0]._links[0].href).toBe(url);
expect(result.log.pages[0]._links[0].text).toBe('Example');
});
});