util.spec.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*import {
  2. extend,
  3. inherit
  4. } from "../../src/util";
  5. describe("util", function () {
  6. it('inherit', () => {
  7. function A() {}
  8. A.prototype = {
  9. render: function () {
  10. console.log('111')
  11. },
  12. setState: function(){}
  13. }
  14. function B() {
  15. }
  16. inherit(B, A)
  17. var b = new B
  18. expect(b).toInstanceOf(B)
  19. expect(b).toInstanceOf(A)
  20. expect(b.render).toBe(A.prototype.render)
  21. expect(b.setState).toA('function')
  22. })
  23. it("oneObject", function () {
  24. expect(oneObject("aa,bb,cc")).toEqual({
  25. aa: 1,
  26. bb: 1,
  27. cc: 1
  28. });
  29. expect(oneObject("")).toEqual({});
  30. expect(oneObject([1, 2, 3], false)).toEqual({
  31. 1: false,
  32. 2: false,
  33. 3: false
  34. });
  35. });
  36. it("extend", function () {
  37. expect(extend({}, {
  38. a: 1,
  39. b: 2
  40. })).toEqual({
  41. a: 1,
  42. b: 2
  43. });
  44. expect(extend({
  45. a: 1
  46. }, null)).toEqual({
  47. a: 1
  48. });
  49. });
  50. it("isFn", function () {
  51. expect(isFn("sss")).toBe(false);
  52. expect(isFn(function a() {})).toBe(true);
  53. });
  54. it("isEventName", () => {
  55. expect(isEventName("onaaa")).toBe(false);
  56. expect(isEventName("onAaa")).toBe(true);
  57. expect(isEventName("xxx")).toBe(false);
  58. });
  59. it("toLowerCase", () => {
  60. expect(toLowerCase("onaaa")).toBe("onaaa");
  61. expect(toLowerCase("onA")).toBe("ona");
  62. expect(toLowerCase("onA")).toBe("ona");
  63. });
  64. it("inherit", () => {
  65. function A() {}
  66. function B() {}
  67. inherit(A, B);
  68. var a = new A;
  69. expect(a instanceof A).toBe(true);
  70. expect(a instanceof B).toBe(true);
  71. });
  72. it("camelize", function () {
  73. expect(typeof camelize).toBe("function");
  74. expect(camelize("aaa-bbb-ccc")).toBe("aaaBbbCcc");
  75. expect(camelize("aaa_bbb_ccc")).toBe("aaaBbbCcc");
  76. expect(camelize("-aaa-bbb-ccc")).toBe("aaaBbbCcc");
  77. expect(camelize("_aaa_bbb_ccc")).toBe("aaaBbbCcc");
  78. expect(camelize("")).toBe("");
  79. });
  80. it("firstLetterLower", function(){
  81. expect(typeof firstLetterLower).toBe("function");
  82. expect(firstLetterLower("WebkitBorderStart")).toBe("webkitBorderStart");
  83. expect(firstLetterLower("")).toBe("");
  84. });
  85. it("toArray", () => {
  86. var dom = {
  87. childNodes: [{}, {}, {}]
  88. };
  89. expect(toArray(dom.childNodes).length).toBe(3);
  90. });
  91. it("getChildContext", () => {
  92. var instance = {
  93. getChildContext: function () {
  94. return {
  95. a: 1
  96. };
  97. }
  98. };
  99. var b = getChildContext(instance, {
  100. b: 4
  101. });
  102. expect(b).toEqual({
  103. a: 1,
  104. b: 4
  105. });
  106. });
  107. it("typeNumber", () => {
  108. var A = function() {};
  109. var a = new A;
  110. expect(typeNumber(void 2)).toBe(0);
  111. expect(typeNumber(null)).toBe(1);
  112. expect(typeNumber(false)).toBe(2);
  113. expect(typeNumber(true)).toBe(2);
  114. expect(typeNumber(1)).toBe(3);
  115. expect(typeNumber("333")).toBe(4);
  116. expect(typeNumber(A)).toBe(5);
  117. expect(typeNumber([])).toBe(7);
  118. expect(typeNumber(a)).toBe(8);
  119. });
  120. });*/