import test from 'ava';
import ReactDOMServer from 'react-dom/server';
import renderHTML from '../index';
const renderTest = (t, reactEl, expectedHTML) => {
t.is(ReactDOMServer.renderToStaticMarkup(reactEl), expectedHTML);
};
const singleElementTest = (t, html) => {
renderTest(t, renderHTML(html), html);
};
test('returns a single React element rendering a provided HTML', t => {
singleElementTest(t, '
' +
'- hihi
' +
'helloworld
react
' +
'
');
});
test('returns an array of React elements if several nodes are provided', t => {
const arr = renderHTML('hihi' +
'helloworld
react
');
t.is(arr.length, 2);
renderTest(t, arr[0], 'hihi');
renderTest(t, arr[1], 'helloworld
react
');
});
test('parse the style attribute when specified as a string', t => {
singleElementTest(t, '' +
'- hihi
' +
'helloworld
react
' +
'
');
});
test('parse comment as undefined', t => {
t.falsy(renderHTML(''));
});
test('parse base64 background url', t => {
singleElementTest(t, '');
});
test('parse script tag', t => {
singleElementTest(t, ``);
});