UNPKG

1 kBJavaScriptView Raw
1import Color from 'color';
2import ReactDOM from 'react-dom';
3import TestUtils from 'react-addons-test-utils';
4
5export function getRenderOutput(element) {
6 const renderer = TestUtils.createRenderer();
7 renderer.render(element);
8 return renderer.getRenderOutput();
9}
10
11export function getElement(output, tagName) {
12 return ReactDOM.findDOMNode(
13 TestUtils.findRenderedDOMComponentWithTag(output, tagName),
14 );
15}
16
17function cleanCSS(css) {
18 return css.replace(/\s*\n\s*/g, '').replace(/\s*([{};:,])\s*/g, '$1');
19}
20
21export function expectCSS(styleElement, css) {
22 // strip newlines and excess whitespace from both to normalize browsers.
23 // IE9, for instance, does not include new lines in innerText.
24 // Also allows us to write our expected CSS cleanly, without worring about the
25 // format of the actual output.
26 expect(cleanCSS(styleElement.innerText)).to.equal(cleanCSS(css));
27}
28
29export function expectColor(actual, expected) {
30 expect(Color(actual).hex()).to.equal(Color(expected).hex());
31}