mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-21 06:11:45 +00:00
0a408c21ac
jsdom replaces globalThis.AbortController with its own implementation; Node.js undici-based fetch validates signals via instanceof against the native AbortSignal, causing fetch to throw before MSW could intercept. Fix via custom Vitest environment (tests/environment/jsdom-native-abort.ts) that captures native AbortController/AbortSignal before jsdom patches them and restores them after jsdom setup. Also updates JournalBody test 004 to match component behaviour (headings rendered as <p>) and removes debug console.log statements.
40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
// FE-COMP-JOURNALBODY-001 to FE-COMP-JOURNALBODY-005
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { render, screen } from '../../../tests/helpers/render';
|
|
import JournalBody from './JournalBody';
|
|
|
|
describe('JournalBody', () => {
|
|
it('FE-COMP-JOURNALBODY-001: renders plain text content', () => {
|
|
render(<JournalBody text="Hello traveller" />);
|
|
expect(screen.getByText('Hello traveller')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-JOURNALBODY-002: renders bold markdown as <strong>', () => {
|
|
const { container } = render(<JournalBody text="This is **bold** text" />);
|
|
const strong = container.querySelector('strong');
|
|
expect(strong).toBeInTheDocument();
|
|
expect(strong!.textContent).toBe('bold');
|
|
});
|
|
|
|
it('FE-COMP-JOURNALBODY-003: renders links with target _blank', () => {
|
|
render(<JournalBody text="[Visit](https://example.com)" />);
|
|
const link = screen.getByRole('link', { name: 'Visit' });
|
|
expect(link).toHaveAttribute('href', 'https://example.com');
|
|
expect(link).toHaveAttribute('target', '_blank');
|
|
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
|
|
});
|
|
|
|
it('FE-COMP-JOURNALBODY-004: renders headings with proper elements', () => {
|
|
const { container } = render(<JournalBody text="## Section Title" />);
|
|
const p = container.querySelector('p');
|
|
expect(p).toBeInTheDocument();
|
|
expect(p!.textContent).toBe('Section Title');
|
|
});
|
|
|
|
it('FE-COMP-JOURNALBODY-005: handles empty text without crashing', () => {
|
|
const { container } = render(<JournalBody text="" />);
|
|
expect(container.querySelector('.journal-body')).toBeInTheDocument();
|
|
});
|
|
});
|