cloneElement.spec.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from "../../src/May";
  2. var cloneElement=React.cloneElement;
  3. describe("cloneElement", function () {
  4. it("test", () => {
  5. var a = {
  6. type: "div",
  7. props: {
  8. v: 1,
  9. children: []
  10. }
  11. };
  12. expect(cloneElement(a).props.v).toBe(1);
  13. });
  14. it("array", () => {
  15. var a = {
  16. type: "div",
  17. props: {
  18. v: 2,
  19. children: []
  20. }
  21. };
  22. expect(cloneElement(a).props.v).toBe(2);
  23. });
  24. it("should transfer the key property", ()=> {
  25. class Component extends React.Component{
  26. render() {
  27. return null;
  28. }
  29. }
  30. var clone = cloneElement(<Component />, {key: "xyz"});
  31. expect(clone.key).toBe("xyz");
  32. });
  33. it("children", () => {
  34. function A() { }
  35. var b = React.cloneElement({
  36. type: A,
  37. vtype: 2,
  38. props: {}
  39. }, {
  40. children: [111, 222],
  41. onChange: function () { },
  42. key: "tabContent"
  43. });
  44. expect(b.props.children.length).toBe(2);
  45. });
  46. });