import { sanitizeString } from '@shared/utils/sanitize'; describe('sanitizeString', () => { it('should return an empty string if input is null or undefined', () => { expect(sanitizeString(null)).toBe(''); expect(sanitizeString(undefined)).toBe(''); expect(sanitizeString('')).toBe(''); }); it('should not modify safe HTML content', () => { const safeHtml = '
Hello, World!
'; expect(sanitizeString(safeHtml)).toBe(safeHtml); }); it('should remove disallowed HTML tags', () => { const dirtyHtml = 'Secure text
'; expect(sanitizeString(dirtyHtml)).toBe('alert("XSS")Secure text
'); }); it('should remove multiple disallowed tags', () => { const dirtyHtml = 'Ok
'; expect(sanitizeString(dirtyHtml)).toBe('body{background:red;}Ok
'); }); it('should remove JavaScript URLs', () => { const dirtyHtml = 'Click here'; expect(sanitizeString(dirtyHtml)).toBe( 'Click here', ); }); });