1
1
const assert = require ( 'assert' ) ;
2
2
const React = require ( 'react' ) ;
3
- const Parser = require ( '../' ) ;
3
+ const parse = require ( '../' ) ;
4
4
const { data, render } = require ( './helpers/' ) ;
5
5
6
6
describe ( 'html-to-react' , ( ) => {
7
7
describe ( 'parser' , ( ) => {
8
8
[ undefined , null , { } , [ ] , 42 ] . forEach ( value => {
9
9
it ( `throws an error if first argument is ${ value } ` , ( ) => {
10
10
assert . throws ( ( ) => {
11
- Parser ( value ) ;
11
+ parse ( value ) ;
12
12
} , TypeError ) ;
13
13
} ) ;
14
14
} ) ;
15
15
16
16
it ( 'returns string if it cannot be parsed as HTML' , ( ) => {
17
- assert . equal ( Parser ( 'foo' ) , 'foo' ) ;
17
+ assert . equal ( parse ( 'foo' ) , 'foo' ) ;
18
18
} ) ;
19
19
20
20
it ( 'converts single HTML element to React' , ( ) => {
21
21
const html = data . html . single ;
22
- const reactElement = Parser ( html ) ;
22
+ const reactElement = parse ( html ) ;
23
23
assert . equal ( render ( reactElement ) , html ) ;
24
24
} ) ;
25
25
26
26
it ( 'converts single HTML element and ignores comment' , ( ) => {
27
27
const html = data . html . single ;
28
28
// comment should be ignored
29
- const reactElement = Parser ( html + data . html . comment ) ;
29
+ const reactElement = parse ( html + data . html . comment ) ;
30
30
assert . equal ( render ( reactElement ) , html ) ;
31
31
} ) ;
32
32
33
33
it ( 'converts multiple HTML elements to React' , ( ) => {
34
34
const html = data . html . multiple ;
35
- const reactElements = Parser ( html ) ;
35
+ const reactElements = parse ( html ) ;
36
36
assert . equal (
37
37
render ( React . createElement ( 'div' , { } , reactElements ) ) ,
38
38
'<div>' + html + '</div>'
@@ -41,26 +41,26 @@ describe('html-to-react', () => {
41
41
42
42
it ( 'converts complex HTML to React' , ( ) => {
43
43
const html = data . html . complex ;
44
- const reactElement = Parser ( data . html . doctype + html ) ;
44
+ const reactElement = parse ( data . html . doctype + html ) ;
45
45
assert . equal ( render ( reactElement ) , html ) ;
46
46
} ) ;
47
47
48
48
it ( 'converts empty <style> to React' , ( ) => {
49
49
const html = '<style></style>' ;
50
- const reactElement = Parser ( html ) ;
50
+ const reactElement = parse ( html ) ;
51
51
assert . equal ( render ( reactElement ) , html ) ;
52
52
} ) ;
53
53
54
54
it ( 'converts SVG to React' , ( ) => {
55
55
const svg = data . svg . complex ;
56
- const reactElement = Parser ( svg ) ;
56
+ const reactElement = parse ( svg ) ;
57
57
assert . equal ( render ( reactElement ) , svg ) ;
58
58
} ) ;
59
59
60
60
it ( 'decodes HTML entities' , ( ) => {
61
61
const encodedEntities = 'asdf & ÿ ü '' ;
62
62
const decodedEntities = "asdf & ÿ ü '" ;
63
- const reactElement = Parser ( '<i>' + encodedEntities + '</i>' ) ;
63
+ const reactElement = parse ( '<i>' + encodedEntities + '</i>' ) ;
64
64
assert . equal ( reactElement . props . children , decodedEntities ) ;
65
65
} ) ;
66
66
} ) ;
@@ -69,7 +69,7 @@ describe('html-to-react', () => {
69
69
describe ( 'replace' , ( ) => {
70
70
it ( 'overrides the element if replace is valid' , ( ) => {
71
71
const html = data . html . complex ;
72
- const reactElement = Parser ( html , {
72
+ const reactElement = parse ( html , {
73
73
replace : node => {
74
74
if ( node . name === 'title' ) {
75
75
return React . createElement ( 'title' , { } , 'Replaced Title' ) ;
@@ -84,7 +84,7 @@ describe('html-to-react', () => {
84
84
85
85
it ( 'does not override the element if replace is invalid' , ( ) => {
86
86
const html = data . html . complex ;
87
- const reactElement = Parser ( html , {
87
+ const reactElement = parse ( html , {
88
88
replace : node => {
89
89
if ( node . attribs && node . attribs . id === 'header' ) {
90
90
return {
@@ -105,3 +105,9 @@ describe('html-to-react', () => {
105
105
} ) ;
106
106
} ) ;
107
107
} ) ;
108
+
109
+ describe ( 'dom-to-react' , ( ) => {
110
+ it ( 'exports domToReact' , ( ) => {
111
+ assert . equal ( parse . domToReact , require ( '../lib/dom-to-react' ) ) ;
112
+ } ) ;
113
+ } ) ;
0 commit comments