ReactCompositeComponentDOMMinimalism-test.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import PropTypes from '../../lib/ReactPropTypes';
  2. import ReactTestUtils from "../../lib/ReactTestUtils";
  3. import React from '../../src/May';
  4. import { render, unmountComponentAtNode, findDOMNode } from '../../src/may-dom/MayDom'
  5. var ReactDOM = {
  6. render: render,
  7. unmountComponentAtNode: unmountComponentAtNode,
  8. findDOMNode: findDOMNode
  9. }
  10. React.render = render;
  11. describe("ReactCompositeComponentDOMMinimalism",function() {
  12. // this.timeout(200000);
  13. var LowerLevelComposite = class extends React.Component {
  14. render() {
  15. return <div>{this.props.children}</div>;
  16. }
  17. };
  18. var MyCompositeComponent = class extends React.Component {
  19. render() {
  20. return <LowerLevelComposite>{this.props.children}</LowerLevelComposite>;
  21. }
  22. };
  23. var expectSingleChildlessDiv = function(instance) {
  24. var el = ReactDOM.findDOMNode(instance);
  25. expect(el.tagName).toBe("DIV");
  26. expect(el.children.length).toBe(0);
  27. };
  28. it("should not render extra nodes for non-interpolated text", () => {
  29. var instance = <MyCompositeComponent>A string child</MyCompositeComponent>;
  30. instance = ReactTestUtils.renderIntoDocument(instance);
  31. expectSingleChildlessDiv(instance);
  32. });
  33. it("should not render extra nodes for non-interpolated text", () => {
  34. var instance = <MyCompositeComponent>{"Interpolated String Child"}</MyCompositeComponent>;
  35. instance = ReactTestUtils.renderIntoDocument(instance);
  36. expectSingleChildlessDiv(instance);
  37. });
  38. it("should not render extra nodes for non-interpolated text", () => {
  39. var instance = (
  40. <MyCompositeComponent>
  41. <ul>This text causes no children in ul, just innerHTML</ul>
  42. </MyCompositeComponent>
  43. );
  44. instance = ReactTestUtils.renderIntoDocument(instance);
  45. var el = ReactDOM.findDOMNode(instance);
  46. expect(el.tagName).toBe("DIV");
  47. expect(el.children.length).toBe(1);
  48. expect(el.children[0].tagName).toBe("UL");
  49. expect(el.children[0].children.length).toBe(0);
  50. });
  51. });