-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathhighlight.test.js
59 lines (46 loc) · 1.6 KB
/
highlight.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
/**
* @jest-environment jsdom
*/
import Highlight from '../src'
import ReactDOM from 'react-dom'
import TestUtils from 'react-dom/test-utils'
import ReactDOMServer from 'react-dom/server'
import React from 'react'
describe('highlight', () => {
test('should display text inside it', () => {
const text = TestUtils.renderIntoDocument(<Highlight>Some text</Highlight>)
expect(ReactDOM.findDOMNode(text).textContent).toBe('Some text')
})
test('should have pre and code tags in markup', () => {
const text = ReactDOMServer.renderToStaticMarkup(
<Highlight>Some text</Highlight>
)
expect(text).toBe('<pre><code>Some text</code></pre>')
})
test('should assign className prop', () => {
const text = ReactDOMServer.renderToStaticMarkup(
<Highlight className="html">Some text</Highlight>
)
expect(text).toBe('<pre><code class="html">Some text</code></pre>')
})
test('should render children in span', () => {
const text = ReactDOMServer.renderToStaticMarkup(
<Highlight element="span">Some text</Highlight>
)
expect(text).toBe('<span>Some text</span>')
})
test('should render innerHTML in span', () => {
const text = ReactDOMServer.renderToStaticMarkup(
<Highlight innerHTML={true} element="span">
Some text
</Highlight>
)
expect(text).toBe('<span>Some text</span>')
})
test('should accept innerHTML prop', () => {
const text = TestUtils.renderIntoDocument(
<Highlight innerHTML={true}>{'<div>Sometext</div>'}</Highlight>
)
expect(ReactDOM.findDOMNode(text).textContent).toBe('Sometext')
})
})