11const assert = require ( 'assert' ) ;
22const React = require ( 'react' ) ;
3- const Parser = require ( '../' ) ;
3+ const parse = require ( '../' ) ;
44const { data, render } = require ( './helpers/' ) ;
55
66describe ( 'html-to-react' , ( ) => {
77 describe ( 'parser' , ( ) => {
88 [ undefined , null , { } , [ ] , 42 ] . forEach ( value => {
99 it ( `throws an error if first argument is ${ value } ` , ( ) => {
1010 assert . throws ( ( ) => {
11- Parser ( value ) ;
11+ parse ( value ) ;
1212 } , TypeError ) ;
1313 } ) ;
1414 } ) ;
1515
1616 it ( 'returns string if it cannot be parsed as HTML' , ( ) => {
17- assert . equal ( Parser ( 'foo' ) , 'foo' ) ;
17+ assert . equal ( parse ( 'foo' ) , 'foo' ) ;
1818 } ) ;
1919
2020 it ( 'converts single HTML element to React' , ( ) => {
2121 const html = data . html . single ;
22- const reactElement = Parser ( html ) ;
22+ const reactElement = parse ( html ) ;
2323 assert . equal ( render ( reactElement ) , html ) ;
2424 } ) ;
2525
2626 it ( 'converts single HTML element and ignores comment' , ( ) => {
2727 const html = data . html . single ;
2828 // comment should be ignored
29- const reactElement = Parser ( html + data . html . comment ) ;
29+ const reactElement = parse ( html + data . html . comment ) ;
3030 assert . equal ( render ( reactElement ) , html ) ;
3131 } ) ;
3232
3333 it ( 'converts multiple HTML elements to React' , ( ) => {
3434 const html = data . html . multiple ;
35- const reactElements = Parser ( html ) ;
35+ const reactElements = parse ( html ) ;
3636 assert . equal (
3737 render ( React . createElement ( 'div' , { } , reactElements ) ) ,
3838 '<div>' + html + '</div>'
@@ -41,32 +41,26 @@ describe('html-to-react', () => {
4141
4242 it ( 'converts complex HTML to React' , ( ) => {
4343 const html = data . html . complex ;
44- const reactElement = Parser ( data . html . doctype + html ) ;
45- assert . equal ( render ( reactElement ) , html ) ;
46- } ) ;
47-
48- it ( 'converts empty <script> to React' , ( ) => {
49- const html = '<script></script>' ;
50- const reactElement = Parser ( html ) ;
44+ const reactElement = parse ( data . html . doctype + html ) ;
5145 assert . equal ( render ( reactElement ) , html ) ;
5246 } ) ;
5347
5448 it ( 'converts empty <style> to React' , ( ) => {
5549 const html = '<style></style>' ;
56- const reactElement = Parser ( html ) ;
50+ const reactElement = parse ( html ) ;
5751 assert . equal ( render ( reactElement ) , html ) ;
5852 } ) ;
5953
6054 it ( 'converts SVG to React' , ( ) => {
6155 const svg = data . svg . complex ;
62- const reactElement = Parser ( svg ) ;
56+ const reactElement = parse ( svg ) ;
6357 assert . equal ( render ( reactElement ) , svg ) ;
6458 } ) ;
6559
6660 it ( 'decodes HTML entities' , ( ) => {
6761 const encodedEntities = 'asdf & ÿ ü '' ;
6862 const decodedEntities = "asdf & ÿ ü '" ;
69- const reactElement = Parser ( '<i>' + encodedEntities + '</i>' ) ;
63+ const reactElement = parse ( '<i>' + encodedEntities + '</i>' ) ;
7064 assert . equal ( reactElement . props . children , decodedEntities ) ;
7165 } ) ;
7266 } ) ;
@@ -75,7 +69,7 @@ describe('html-to-react', () => {
7569 describe ( 'replace' , ( ) => {
7670 it ( 'overrides the element if replace is valid' , ( ) => {
7771 const html = data . html . complex ;
78- const reactElement = Parser ( html , {
72+ const reactElement = parse ( html , {
7973 replace : node => {
8074 if ( node . name === 'title' ) {
8175 return React . createElement ( 'title' , { } , 'Replaced Title' ) ;
@@ -90,7 +84,7 @@ describe('html-to-react', () => {
9084
9185 it ( 'does not override the element if replace is invalid' , ( ) => {
9286 const html = data . html . complex ;
93- const reactElement = Parser ( html , {
87+ const reactElement = parse ( html , {
9488 replace : node => {
9589 if ( node . attribs && node . attribs . id === 'header' ) {
9690 return {
@@ -111,3 +105,9 @@ describe('html-to-react', () => {
111105 } ) ;
112106 } ) ;
113107} ) ;
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