-
-
Notifications
You must be signed in to change notification settings - Fork 176
/
index.component.spec.tsx
84 lines (69 loc) · 1.65 KB
/
index.component.spec.tsx
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
import Markdown from './index'
import * as React from 'react'
import * as 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>
Hello.
</em>
`)
})
it('handles a no-children scenario', () => {
render(<Markdown>{''}</Markdown>)
expect(root.innerHTML).toMatchInlineSnapshot(`
<span>
</span>
`)
})
it('accepts options', () => {
class FakeParagraph extends React.Component<React.PropsWithChildren<{}>> {
render() {
return <p className="foo">{this.props.children}</p>
}
}
render(
<Markdown options={{ overrides: { p: { component: FakeParagraph } } }}>
_Hello._
</Markdown>
)
expect(root.innerHTML).toMatchInlineSnapshot(`
<em>
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>
<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 id="hello"
class="foo"
>
Hello
</h1>
`)
})