-
Notifications
You must be signed in to change notification settings - Fork 39
/
test.js
77 lines (63 loc) · 1.63 KB
/
test.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
// @flow
'use strict';
const md = require('./');
const React = require('react');
const ReactDOMServer = require('react-dom/server');
const renderToStaticMarkup = ReactDOMServer.renderToStaticMarkup;
const element = React.createElement('div', null, 'MyComponent');
test('blocks', () => {
expect(renderToStaticMarkup(md`
# Heading
${element}
`)).toBe('<div><h1>Heading</h1><div>MyComponent</div></div>');
expect(renderToStaticMarkup(md`
> ${element}
`)).toBe('<div><blockquote><div>MyComponent</div></blockquote></div>');
});
test('regular paragraphs', () => {
expect(renderToStaticMarkup(md`
test
`)).toBe('<div><p>test</p></div>');
});
test('non-blocks', () => {
expect(() => {
renderToStaticMarkup(md`
# Heading ${element}
`)
}).toThrow();
expect(() => {
renderToStaticMarkup(md`
Paragraph ${element}
`)
}).toThrow();
expect(() => {
renderToStaticMarkup(md`
\`\`\`
${element}
\`\`\`
`)
}).toThrow();
expect(() => {
renderToStaticMarkup(md`
_${element}_
`);
}).toThrow();
expect(() => {
renderToStaticMarkup(md`
\`${element}\`
`);
}).toThrow();
});
test('customize', () => {
const customMd = md.customize({
renderers: {
heading: props => React.createElement('h' + props.level, { className: 'fancy' }, props.children),
paragraph: props => React.createElement('p', { className: 'blink' }, props.children)
}
});
expect(renderToStaticMarkup(customMd`
# Heading
${element}
paragraph
`)).toBe('<div><h1 class="fancy">Heading</h1><div>MyComponent</div><p class="blink">paragraph</p></div>');
});