import {describe, expect, test} from 'vitest';
import {DOM} from './dom.ts';
describe('DOM', () => {
describe('sanitize', () => {
test('should not fail on empty string', () => {
const input = '';
const output = DOM.sanitize(input);
expect(output).toBe('');
});
test('should remove script tags', () => {
const input = '';
const output = DOM.sanitize(input);
expect(output).toBe('');
});
test('should remove script tags from nested elements', () => {
const input = '
';
const output = DOM.sanitize(input);
expect(output).toBe('');
});
test('should remove potentially dangerous attributes', () => {
const input = 'click me';
const output = DOM.sanitize(input);
expect(output).toBe('click me');
});
test('should remove potentially dangerous attributes from img', () => {
const input = '
';
const output = DOM.sanitize(input);
expect(output).toBe('
');
});
test('should remove potentially dangerous attributes from nested elements', () => {
const input = '';
const output = DOM.sanitize(input);
expect(output).toBe('');
});
test('should remove multiple consecutive dangerous attributes', () => {
const input = 'x ';
const output = DOM.sanitize(input);
expect(output).not.toContain('onload');
expect(output).not.toContain('ontoggle');
});
test('should remove iframe tags', () => {
const input = '';
const output = DOM.sanitize(input);
expect(output).toBe('');
});
test('should remove iframe tags from nested elements', () => {
const input = '';
const output = DOM.sanitize(input);
expect(output).toBe('');
});
test('should remove srcdoc attributes', () => {
const input = '';
const output = DOM.sanitize(input);
expect(output).toBe('');
});
test('should remove dangerous attributes that follow a removed attribute', () => {
const input = 'click me';
const output = DOM.sanitize(input);
expect(output).toBe('click me');
});
});
});