bdd_test.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>script.aculo.us Unit test file</title>
  6. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  7. <script src="../../lib/prototype.js" type="text/javascript"></script>
  8. <script src="../../src/scriptaculous.js" type="text/javascript"></script>
  9. <script src="../../src/unittest.js" type="text/javascript"></script>
  10. <link rel="stylesheet" href="../test.css" type="text/css" />
  11. </head>
  12. <body>
  13. <h1>script.aculo.us Unit test file</h1>
  14. <!-- Log output -->
  15. <div id="testlog"> </div>
  16. <div id="d">initial</div>
  17. <!-- Tests follow -->
  18. <script type="text/javascript" language="javascript" charset="utf-8">
  19. // <![CDATA[
  20. var moo = 0;
  21. var assertMethods = [];
  22. for(method in Test.Unit.Assertions.prototype) {
  23. if(/^assert/.test(method)) assertMethods.push(method);
  24. }
  25. var testObj = {
  26. isNice: function(){
  27. return true;
  28. },
  29. isBroken: function(){
  30. return false;
  31. }
  32. }
  33. Test.context("BDD-style testing",{
  34. setup: function() {
  35. $('d').update('setup!');
  36. moo++;
  37. },
  38. teardown: function() {
  39. moo--;
  40. },
  41. 'should run setup before each specification': function(){
  42. assert($('d').innerHTML == 'setup!');
  43. assert(moo == 1);
  44. },
  45. 'should run teardown after each specification': function(){
  46. assert(moo == 1);
  47. },
  48. 'should provide extensions to tie in isSomething and respondsTo object methods': function(){
  49. Object.extend(testObj, Test.BDDMethods);
  50. testObj.shouldBe('nice');
  51. testObj.shouldNotBe('broken');
  52. testObj.shouldRespondTo('isNice');
  53. testObj.shouldRespondTo('isBroken');
  54. },
  55. 'should automatically add extensions to strings': function(){
  56. 'a'.shouldEqual('a');
  57. 'a'.shouldNotEqual('b');
  58. 'a'.shouldNotBeNull();
  59. 'a'.shouldBeA(String);
  60. var aString = 'boo!';
  61. aString.shouldEqual('boo!');
  62. aString.shouldBeA(String);
  63. aString.shouldNotBeA(Number);
  64. },
  65. 'should automatically add extensions to numbers': function(){
  66. var n = 123;
  67. n.shouldEqual(123);
  68. n.shouldNotEqual(4);
  69. n.shouldBeA(Number);
  70. n.shouldNotBeA(Test);
  71. },
  72. 'should automatically add extensions to arrays': function(){
  73. ['a'].shouldNotBeA(String);
  74. [1,2,3].shouldBeAn(Array);
  75. [1,2,3].shouldEqualEnum([1,2,3]);
  76. },
  77. 'should automatically add extensions to booleans': function(){
  78. var theTruth = true;
  79. var lies = false;
  80. theTruth.shouldNotBeA(String);
  81. lies.shouldBeA(Boolean);
  82. 'false'.shouldNotBeA(Boolean);
  83. theTruth.shouldEqual(true);
  84. lies.shouldNotEqual(true);
  85. },
  86. 'should support the eval() method': function(){
  87. eval('2*2').shouldEqual(4);
  88. },
  89. 'should support equality assertion': function(){
  90. assertEqual(1, 1);
  91. assertEqual('a', 'a');
  92. assertEqual(1, '1');
  93. var x = 1;
  94. var y = 1;
  95. assertEqual(1, x)
  96. assertEqual(x, y);
  97. },
  98. 'should provide all assertions': function(){
  99. assertMethods.each(function(m){
  100. assert(typeof this[m] == 'function');
  101. }.bind(this));
  102. },
  103. 'should support deferred execution': function(){
  104. wait(10,function(){
  105. 'a'.shouldEqual('a');
  106. });
  107. wait(10,function(){
  108. 'a'.shouldEqual('a');
  109. wait(10,function(){
  110. 'a'.shouldEqual('a');
  111. wait(10,function(){
  112. 'a'.shouldEqual('a');
  113. });
  114. });
  115. });
  116. }
  117. });
  118. // ]]>
  119. </script>
  120. </body>
  121. </html>