This repository has been archived by the owner on Nov 4, 2019. It is now read-only.
forked from quantizor/markdown-to-jsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.component.spec.js
95 lines (70 loc) · 1.64 KB
/
index.component.spec.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import Markdown from './index';
import React from 'react';
import ReactDOM from 'react-dom';
const root = document.body.appendChild(document.createElement('div'));
function render(jsx) {
return ReactDOM.render(jsx, root);
}
afterEach(() => ReactDOM.unmountComponentAtNode(root));
it('accepts markdown content', () => {
render(<Markdown>_Hello._</Markdown>);
expect(root.innerHTML).toMatchInlineSnapshot(`
<em data-reactroot>
Hello.
</em>
`);
});
it('handles a no-children scenario', () => {
render(<Markdown>{''}</Markdown>);
expect(root.innerHTML).toMatchInlineSnapshot(`
<span data-reactroot>
</span>
`);
});
it('accepts options', () => {
class FakeParagraph extends React.Component {
render() {
return <p className="foo">{this.props.children}</p>;
}
}
render(
<Markdown options={{ overrides: { p: { component: FakeParagraph } } }}>
_Hello._
</Markdown>
);
expect(root.innerHTML).toMatchInlineSnapshot(`
<em data-reactroot>
Hello.
</em>
`);
});
it('merges className overrides, rather than overwriting', () => {
const code = ['```js', 'foo', '```'].join('\n');
render(
<Markdown
options={{
overrides: { code: { props: { className: 'foo' } } },
}}
>
{code}
</Markdown>
);
expect(root.innerHTML).toMatchInlineSnapshot(`
<pre data-reactroot>
<code class="lang-js foo">
foo
</code>
</pre>
`);
});
it('passes along any additional props to the rendered wrapper element', () => {
render(<Markdown className="foo"># Hello</Markdown>);
expect(root.innerHTML).toMatchInlineSnapshot(`
<h1 data-reactroot
id="hello"
class="foo"
>
Hello
</h1>
`);
});