import PropTypes from '../../lib/ReactPropTypes';
import ReactTestUtils from "../../lib/ReactTestUtils";
import React from '../../src/May';
import { render, unmountComponentAtNode, findDOMNode } from '../../src/may-dom/MayDom';
import {shallowCompare} from '../../src/PureComponent';
var ReactDOM = {
render: render,
unmountComponentAtNode: unmountComponentAtNode,
findDOMNode: findDOMNode
}
React.render = render;
// import React from "../../dist/ReactANU";
// var ReactDOM = React;
// var ReactTestUtils = {
// renderIntoDocument: function (element) {
// var div = document.createElement("div");
// return React.render(element, div);
// }
// };
//https://github.com/facebook/react/blob/master/src/isomorphic/children/__tests__/ReactChildren-test.js
describe("ReactComponent", function() {
// this.timeout(200000);
it("should not produce child DOM nodes for null and false", function() {
class Component1 extends React.Component {
render() {
return null;
}
}
class Component2 extends React.Component {
render() {
return false;
}
}
var container1 = document.createElement("div");
ReactDOM.render(, container1);
expect(container1.children.length).toBe(0);
var container2 = document.createElement("div");
ReactDOM.render(, container2);
expect(container2.children.length).toBe(0);
});
it("works when switching components", () => {
var assertions = 0;
class Inner extends React.Component {
render() {
return ;
}
componentDidMount() {
// Make sure the DOM node resolves properly even if we're replacing a
// `null` component
expect(ReactDOM.findDOMNode(this)).not.toBe(null);
assertions++;
}
componentWillUnmount() {
// Even though we're getting replaced by `null`, we haven't been
// replaced yet!
expect(ReactDOM.findDOMNode(this)).not.toBe(null);
assertions++;
}
}
class Wrapper extends React.Component {
render() {
return this.props.showInner ? : null;
}
}
var el = document.createElement("div");
var component;
// Render the component...
component = ReactDOM.render(, el);
expect(ReactDOM.findDOMNode(component)).not.toBe(null);
// Switch to null...
component = ReactDOM.render(, el);
// expect(ReactDOM.findDOMNode(component).nodeName).toBe("#comment");
// ...then switch back.
component = ReactDOM.render(, el);
expect(ReactDOM.findDOMNode(component)).not.toBe(null);
expect(assertions).toBe(3);
});
it("preserves the dom node during updates", () => {
class Empty extends React.Component {
render() {
return null;
}
}
var container = document.createElement("div");
ReactDOM.render(, container);
var noscript1 = container.firstChild;
expect(noscript1.nodeName).toBe("#comment");
// This update shouldn't create a DOM node
ReactDOM.render(, container);
var noscript2 = container.firstChild;
expect(noscript2.nodeName).toBe("#comment");
expect(noscript1).toBe(noscript2);
});
});