34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { renderMarkdownToHtml } from '../../frontend/src/app/core/services/markdown.pure';
|
|
|
|
describe('renderMarkdownToHtml', () => {
|
|
it('renders headings', () => {
|
|
expect(renderMarkdownToHtml('# Hello')).toContain('<h1>Hello</h1>');
|
|
});
|
|
|
|
it('renders bold and italic', () => {
|
|
const out = renderMarkdownToHtml('**bold** and *italic*');
|
|
expect(out).toContain('<strong>bold</strong>');
|
|
expect(out).toContain('<em>italic</em>');
|
|
});
|
|
|
|
it('renders safe links', () => {
|
|
expect(renderMarkdownToHtml('[a](https://example.com)')).toContain('href="https://example.com"');
|
|
});
|
|
|
|
it('strips <script> tags', () => {
|
|
const out = renderMarkdownToHtml('<script>alert(1)</script>safe');
|
|
expect(out).not.toContain('<script>');
|
|
expect(out).toContain('safe');
|
|
});
|
|
|
|
it('strips javascript: hrefs', () => {
|
|
const out = renderMarkdownToHtml('[click](javascript:alert(1))');
|
|
expect(out).not.toMatch(/href="javascript:/i);
|
|
});
|
|
|
|
it('handles empty/null/undefined input', () => {
|
|
expect(renderMarkdownToHtml('')).toBeDefined();
|
|
expect(renderMarkdownToHtml(null as unknown as string)).toBeDefined();
|
|
expect(renderMarkdownToHtml(undefined as unknown as string)).toBeDefined();
|
|
});
|
|
}); |