-
Notifications
You must be signed in to change notification settings - Fork 53
/
server-render-test.js
33 lines (28 loc) · 1.32 KB
/
server-render-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
const React = require('react');
const ReactDOMServer = require('react-dom/server');
const AnimateHeight = require('./dist/cjs/index.js').default;
const example = React.createElement('div', null, [
React.createElement(AnimateHeight, { key: '1', height: 0 }, 'Hello World'),
React.createElement(
AnimateHeight,
{ key: '2', height: 'auto' },
'Hello World'
),
React.createElement(AnimateHeight, { key: '3', height: 100 }, 'Hello World'),
]);
const renderedString = ReactDOMServer.renderToString(example);
const expectedString =
'<div><div aria-hidden="true" class="rah-static rah-static--height-zero " style="height:0;overflow:hidden"><div>Hello World</div></div><div aria-hidden="false" class="rah-static rah-static--height-auto " style="height:auto;overflow:visible"><div>Hello World</div></div><div aria-hidden="false" class="rah-static rah-static--height-specific " style="height:100px;overflow:hidden"><div>Hello World</div></div></div>';
const reset = '\x1b[0m';
const red = '\x1b[31m';
const green = '\x1b[32m';
if (renderedString === expectedString) {
console.log(green + '\nTest passed\n' + reset);
} else {
console.log('\nRendered:');
console.log(red + renderedString + reset);
console.log('\nExpected:');
console.log(green + expectedString + reset);
console.log('\n', red);
throw new Error('Test failed');
}