32 lines
1 KiB
JavaScript
32 lines
1 KiB
JavaScript
import { test, expect } from 'bun:test';
|
|
import { DOMParser } from './setup.js';
|
|
import { makeTree, join } from '../utils.js';
|
|
|
|
test('makeTree parses HTML correctly', () => {
|
|
const html = '<html><body><div id="test">Hello</div></body></html>';
|
|
const doc = makeTree(html, DOMParser);
|
|
const div = doc.querySelector('#test');
|
|
expect(div).toBeTruthy();
|
|
expect(div.textContent).toBe('Hello');
|
|
});
|
|
|
|
test('makeTree throws on non-string input', () => {
|
|
expect(() => makeTree(123, DOMParser)).toThrow(TypeError);
|
|
});
|
|
|
|
test('join combines URL parts correctly', () => {
|
|
expect(join('a', 'b', 'c')).toBe('/a/b/c');
|
|
expect(join('/a/', '/b/', '/c/')).toBe('/a/b/c');
|
|
expect(join('', 'a', '', 'b')).toBe('/a/b');
|
|
expect(join()).toBe('/');
|
|
});
|
|
|
|
test('join handles empty strings', () => {
|
|
expect(join('', '', '')).toBe('/');
|
|
expect(join('a', '', 'b')).toBe('/a/b');
|
|
});
|
|
|
|
test('join handles leading/trailing slashes', () => {
|
|
expect(join('/a', 'b/', '/c')).toBe('/a/b/c');
|
|
expect(join('//a//', '//b//', '//c//')).toBe('/a/b/c');
|
|
});
|