ReactUpdates-test.jsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. import { shallowCompare } from '../../src/PureComponent';
  6. var ReactDOM = {
  7. render: render,
  8. unmountComponentAtNode: unmountComponentAtNode,
  9. findDOMNode: findDOMNode
  10. }
  11. React.render = render;
  12. // import React from "../../dist/ReactANU";
  13. // var ReactDOM = React;
  14. // var ReactTestUtils = {
  15. // renderIntoDocument: function (element) {
  16. // var div = document.createElement("div");
  17. // return React.render(element, div);
  18. // }
  19. // };
  20. //https://github.com/facebook/react/blob/master/src/renderers/dom/test/__tests__/ReactTestUtils-test.js
  21. describe("ReactUpdates", function() {
  22. // this.timeout(200000);
  23. // before(async () => {
  24. // await beforeHook();
  25. // });
  26. // after(async () => {
  27. // await afterHook(false);
  28. // });
  29. /**
  30. * Counts clicks and has a renders an item for each click. Each item rendered
  31. * has a ref of the form "clickLogN".
  32. */
  33. it('should not reconcile children passed via props', () => {
  34. var numMiddleRenders = 0;
  35. var numBottomRenders = 0;
  36. class Top extends React.Component {
  37. render() {
  38. return <Middle><Bottom /></Middle>;
  39. }
  40. }
  41. class Middle extends React.Component {
  42. componentDidMount() {
  43. this.forceUpdate();
  44. }
  45. render() {
  46. numMiddleRenders++;
  47. return React.Children.only(this.props.children);
  48. }
  49. }
  50. class Bottom extends React.Component {
  51. render() {
  52. numBottomRenders++;
  53. return null;
  54. }
  55. }
  56. ReactTestUtils.renderIntoDocument(<Top />);
  57. expect(numMiddleRenders).toBe(2);
  58. // expect(numBottomRenders).toBe(1);
  59. expect(numBottomRenders).toBe(2);
  60. });
  61. })