Browse Source

Use custom component in tests

react-dom-peer-dep
Luke Childs 7 years ago
parent
commit
8b449f7998
  1. 12
      test/react-jsdom.js

12
test/react-jsdom.js

@ -3,6 +3,12 @@ import Window from 'window';
import React from 'react'; import React from 'react';
import ReactJSDOM from 'this'; import ReactJSDOM from 'this';
class TestComponent extends React.Component {
render() {
return <div>hi</div>;
}
}
test('ReactJSDOM is a object', t => { test('ReactJSDOM is a object', t => {
t.is(typeof ReactJSDOM, 'object'); t.is(typeof ReactJSDOM, 'object');
}); });
@ -10,20 +16,20 @@ test('ReactJSDOM is a object', t => {
test('ReactJSDOM cleans up globals', t => { test('ReactJSDOM cleans up globals', t => {
global.window = 'foo'; global.window = 'foo';
global.document = 'bar'; global.document = 'bar';
ReactJSDOM.render(<div>hi</div>); ReactJSDOM.render(<TestComponent/>);
t.is(global.window, 'foo'); t.is(global.window, 'foo');
t.is(global.document, 'bar'); t.is(global.document, 'bar');
}); });
test('ReactJSDOM renders a React Component', t => { test('ReactJSDOM renders a React Component', t => {
const elem = ReactJSDOM.render(<div>hi</div>); const elem = ReactJSDOM.render(<TestComponent/>);
t.is(elem.nodeName, 'DIV'); t.is(elem.nodeName, 'DIV');
t.is(elem.textContent, 'hi'); t.is(elem.textContent, 'hi');
}); });
test('ReactJSDOM allows window instance to be passed in', t => { test('ReactJSDOM allows window instance to be passed in', t => {
const window = new Window(); const window = new Window();
const elem = ReactJSDOM.render(<div>hi</div>, window); const elem = ReactJSDOM.render(<TestComponent/>, window);
t.is(elem, window.document.getElementById('root').children[0]); t.is(elem, window.document.getElementById('root').children[0]);
t.is(elem.nodeName, 'DIV'); t.is(elem.nodeName, 'DIV');
t.is(elem.textContent, 'hi'); t.is(elem.textContent, 'hi');

Loading…
Cancel
Save