-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeHighlighter.test.tsx
More file actions
54 lines (47 loc) · 1.53 KB
/
CodeHighlighter.test.tsx
File metadata and controls
54 lines (47 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '../test-utils';
vi.mock('react-syntax-highlighter/dist/esm/prism-light', () => {
const MockHighlighter = ({
children,
language,
...props
}: {
children: string;
language: string;
style?: object;
customStyle?: object;
}) => (
<pre data-testid="syntax-highlighter" data-language={language} {...props}>
{children}
</pre>
);
MockHighlighter.registerLanguage = vi.fn();
return { default: MockHighlighter };
});
vi.mock('react-syntax-highlighter/dist/esm/styles/prism', () => ({
oneLight: {},
}));
vi.mock('react-syntax-highlighter/dist/esm/languages/prism/python', () => ({
default: {},
}));
import CodeHighlighter from './CodeHighlighter';
describe('CodeHighlighter', () => {
it('renders without crashing', () => {
render(<CodeHighlighter code="x = 1" />);
expect(screen.getByTestId('syntax-highlighter')).toBeInTheDocument();
});
it('renders the provided code text', () => {
const code = 'import matplotlib.pyplot as plt\nplt.show()';
render(<CodeHighlighter code={code} />);
const highlighter = screen.getByTestId('syntax-highlighter');
expect(highlighter).toHaveTextContent('import matplotlib.pyplot as plt');
expect(highlighter).toHaveTextContent('plt.show()');
});
it('sets language to python', () => {
render(<CodeHighlighter code="print('hello')" />);
expect(screen.getByTestId('syntax-highlighter')).toHaveAttribute(
'data-language',
'python'
);
});
});