Guest User

Untitled

a guest
Feb 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. Screw.Unit(function() {
  2. describe("Print", function() {
  3. describe('when given undefined', function() {
  4. it("returns 'undefined'", function() {
  5. expect($.print(undefined)).to(equal, 'undefined');
  6. });
  7. });
  8.  
  9. describe('when given null', function() {
  10. it("returns 'null'", function() {
  11. expect($.print(null)).to(equal, 'null');
  12. });
  13. });
  14.  
  15. describe('when given a number', function() {
  16. it("returns the string representation of the number", function() {
  17. expect($.print(1)).to(equal, '1');
  18. expect($.print(1.01)).to(equal, '1.01');
  19. expect($.print(-1)).to(equal, '-1');
  20. });
  21. });
  22.  
  23. describe('when given a boolean', function() {
  24. it("returns the string representation of the boolean", function() {
  25. expect($.print(true)).to(equal, 'true');
  26. expect($.print(false)).to(equal, 'false');
  27. });
  28. });
  29.  
  30. describe('when given a string', function() {
  31. it("returns the string, quoted", function() {
  32. expect($.print('asdf')).to(equal, '"asdf"');
  33. });
  34.  
  35. describe('when the string is longer than the [max_string] option', function() {
  36. it("returns the string, truncated", function() {
  37. expect($.print('asdf', { max_string: 3 })).to(equal, '"asd..."');
  38. });
  39. });
  40.  
  41. describe('when the strings has quotes or escaped characters', function() {
  42. it("returns the string, with quotes and escaped characters escaped", function() {
  43. expect($.print('as"df')).to(equal, '"as\\"df"');
  44. expect($.print('as\tdf')).to(equal, '"as\\tdf"');
  45. });
  46. });
  47. });
  48.  
  49. describe('when given a function', function() {
  50. it("returns the function's signature", function() {
  51. expect($.print(function() {})).to(equal, 'function ()');
  52. expect($.print(function foo() {})).to(equal, 'function foo()');
  53. expect($.print(function foo(bar) {})).to(equal, 'function foo(bar)');
  54. });
  55. });
  56.  
  57. describe('when given a RegExp', function() {
  58. it('should print the regexp', function() {
  59. expect($.print(/abc/i)).to(equal, '/abc/i');
  60. });
  61. });
  62.  
  63. describe('when given NaN', function() {
  64. it('should print the string "NaN"', function() {
  65. expect($.print(NaN)).to(equal, 'NaN');
  66. });
  67. });
  68.  
  69. describe('when given an element', function() {
  70. it("returns the string representation of the element", function() {
  71. expect($.print($('<div>').get(0))).to(equal, '<div>');
  72. expect($.print($('<div foo="bar">').get(0))).to(equal, '<div>');
  73. expect($.print($('<div class="foo" id="bar">').get(0))).to(equal, '<div class="foo" id="bar">');
  74. });
  75.  
  76. describe('when the element is an img', function() {
  77. it('prints out the img src attribute', function() {
  78. expect($.print($('<img src="test.png">'))).to(match, /<img src=".+?test.png">/);
  79. })
  80. });
  81. });
  82.  
  83. describe('when given an array', function() {
  84. it("returns the printed elements, comma separated, encircled by square brackets", function() {
  85. expect($.print([])).to(equal, '[]');
  86. expect($.print([1])).to(equal, '[ 1 ]');
  87. expect($.print([1, 2, 3])).to(equal, '[ 1, 2, 3 ]');
  88. });
  89.  
  90. describe('when the array is longer than the [max_array] option', function() {
  91. it("returns the printed array, truncated", function() {
  92. expect($.print([1, 2, 3, 4], { max_array: 2 })).to(equal, '[ 1, 2, 2 more... ]');
  93. });
  94. });
  95.  
  96. describe('when the array has arrays as its elements', function() {
  97. it("returns the recursively printed array", function() {
  98. expect($.print([[]])).to(equal, '[ [] ]');
  99. expect($.print([ [1, 2, 3], 4 ])).to(equal, '[ [ 1, 2, 3 ], 4 ]');
  100. });
  101. });
  102.  
  103. describe('when the array has objects as its elements', function() {
  104. it("returns recursively printed array", function() {
  105. expect($.print([{}])).to(equal, '[ {} ]');
  106. expect($.print([ { foo: 'bar' }, 'baz' ])).to(equal, '[ { foo: "bar" }, "baz" ]');
  107. });
  108. });
  109. });
  110.  
  111. describe('when given arguments', function() {
  112. it("returns the printed array of elements ", function() {
  113. var args = null;
  114. (function(){ args = arguments })(1,2,3);
  115. expect($.print(args)).to(equal, '[ 1, 2, 3 ]');
  116. });
  117. });
  118.  
  119. describe('when given a jQuery', function() {
  120. it("returns the printed array of elements engirthed in '$()'", function() {
  121. expect($.print($('<div>'))).to(equal, '$([ <div> ])');
  122. });
  123. });
  124.  
  125. describe('when given a NodeList', function() {
  126. it("returns the printed array of elements in the list", function() {
  127. expect($.print(document.getElementsByTagName('body'))).to(equal, '[ <body> ]');
  128. });
  129. });
  130.  
  131. describe('when given an object', function() {
  132. it("returns the keys and values of the object, enraptured with curly braces", function() {
  133. expect($.print({})).to(equal, '{}');
  134. expect($.print({ foo: 1, bar: 2 })).to(equal, '{ foo: 1, bar: 2 }');
  135. });
  136.  
  137. describe('when the values of the object are non-primitive', function() {
  138. it("recursively prints the keys and values", function() {
  139. expect($.print({ foo: [1, 2] })).to(equal, '{ foo: [ 1, 2 ] }');
  140. });
  141.  
  142. describe('when the object has circular references', function() {
  143. it("returns elipses for circularities", function() {
  144. var circular = {};
  145. circular[0] = circular;
  146. expect($.print(circular)).to(equal, '{ 0: ... }');
  147. });
  148. });
  149. });
  150. });
  151. });
  152. });
Add Comment
Please, Sign In to add comment