PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/test/test.js

https://bitbucket.org/jxck/word-cards
JavaScript | 205 lines | 176 code | 28 blank | 1 comment | 5 complexity | 2900e26ac4166ef7512ff502bb5f0b74 MD5 | raw file
  1. test("module without setup/teardown (default)", function() {
  2. expect(1);
  3. ok(true);
  4. });
  5. test("expect in test", 3, function() {
  6. ok(true);
  7. ok(true);
  8. ok(true);
  9. });
  10. test("expect in test", 1, function() {
  11. ok(true);
  12. });
  13. module("setup test", {
  14. setup: function() {
  15. ok(true);
  16. }
  17. });
  18. test("module with setup", function() {
  19. expect(2);
  20. ok(true);
  21. });
  22. var state;
  23. module("setup/teardown test", {
  24. setup: function() {
  25. state = true;
  26. ok(true);
  27. },
  28. teardown: function() {
  29. ok(true);
  30. }
  31. });
  32. test("module with setup/teardown", function() {
  33. expect(3);
  34. ok(true);
  35. });
  36. module("setup/teardown test 2");
  37. test("module without setup/teardown", function() {
  38. expect(1);
  39. ok(true);
  40. });
  41. if (typeof setTimeout !== 'undefined') {
  42. state = 'fail';
  43. module("teardown and stop", {
  44. teardown: function() {
  45. equal(state, "done", "Test teardown.");
  46. }
  47. });
  48. test("teardown must be called after test ended", function() {
  49. expect(1);
  50. stop();
  51. setTimeout(function() {
  52. state = "done";
  53. start();
  54. }, 13);
  55. });
  56. module("async setup test", {
  57. setup: function() {
  58. stop();
  59. setTimeout(function(){
  60. ok(true);
  61. start();
  62. }, 500);
  63. }
  64. });
  65. asyncTest("module with async setup", function() {
  66. expect(2);
  67. ok(true);
  68. start();
  69. });
  70. module("async teardown test", {
  71. teardown: function() {
  72. stop();
  73. setTimeout(function(){
  74. ok(true);
  75. start();
  76. }, 500);
  77. }
  78. });
  79. asyncTest("module with async teardown", function() {
  80. expect(2);
  81. ok(true);
  82. start();
  83. });
  84. } // end setTimeout tests
  85. if (typeof asyncTest !== 'undefined') {
  86. module("asyncTest");
  87. asyncTest("asyncTest", function() {
  88. expect(2);
  89. ok(true);
  90. setTimeout(function() {
  91. state = "done";
  92. ok(true);
  93. start();
  94. }, 13);
  95. });
  96. asyncTest("asyncTest", 2, function() {
  97. ok(true);
  98. setTimeout(function() {
  99. state = "done";
  100. ok(true);
  101. start();
  102. }, 13);
  103. });
  104. } // end asyncTest tests
  105. module("save scope", {
  106. setup: function() {
  107. this.foo = "bar";
  108. },
  109. teardown: function() {
  110. deepEqual(this.foo, "bar");
  111. }
  112. });
  113. test("scope check", function() {
  114. expect(2);
  115. deepEqual(this.foo, "bar");
  116. });
  117. module("simple testEnvironment setup", {
  118. foo: "bar",
  119. bugid: "#5311" // example of meta-data
  120. });
  121. test("scope check", function() {
  122. deepEqual(this.foo, "bar");
  123. });
  124. test("modify testEnvironment",function() {
  125. this.foo="hamster";
  126. });
  127. test("testEnvironment reset for next test",function() {
  128. deepEqual(this.foo, "bar");
  129. });
  130. module("testEnvironment with object", {
  131. options:{
  132. recipe:"soup",
  133. ingredients:["hamster","onions"]
  134. }
  135. });
  136. test("scope check", function() {
  137. deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions"]}) ;
  138. });
  139. test("modify testEnvironment",function() {
  140. // since we do a shallow copy, the testEnvironment can be modified
  141. this.options.ingredients.push("carrots");
  142. });
  143. test("testEnvironment reset for next test",function() {
  144. deepEqual(this.options, {recipe:"soup",ingredients:["hamster","onions","carrots"]}, "Is this a bug or a feature? Could do a deep copy") ;
  145. });
  146. module("testEnvironment tests");
  147. function makeurl() {
  148. var testEnv = QUnit.current_testEnvironment;
  149. var url = testEnv.url || 'http://example.com/search';
  150. var q = testEnv.q || 'a search test';
  151. return url + '?q='+encodeURIComponent(q);
  152. }
  153. test("makeurl working",function() {
  154. equal( QUnit.current_testEnvironment, this, 'The current testEnvironment is global');
  155. equal( makeurl(), 'http://example.com/search?q=a%20search%20test', 'makeurl returns a default url if nothing specified in the testEnvironment');
  156. });
  157. module("testEnvironment with makeurl settings", {
  158. url:'http://google.com/',
  159. q:'another_search_test'
  160. });
  161. test("makeurl working with settings from testEnvironment", function() {
  162. equal( makeurl(), 'http://google.com/?q=another_search_test', 'rather than passing arguments, we use test metadata to form the url');
  163. });
  164. test("each test can extend the module testEnvironment", {
  165. q:'hamstersoup'
  166. }, function() {
  167. equal( makeurl(), 'http://google.com/?q=hamstersoup', 'url from module, q from test');
  168. });
  169. module("jsDump");
  170. test("jsDump output", function() {
  171. equals( QUnit.jsDump.parse([1, 2]), "[ 1, 2 ]" );
  172. equals( QUnit.jsDump.parse({top: 5, left: 0}), "{ \"top\": 5, \"left\": 0 }" );
  173. if (typeof document !== 'undefined') {
  174. equals( QUnit.jsDump.parse(document.getElementById("qunit-header")), "<h1 id=\"qunit-header\"></h1>" );
  175. equals( QUnit.jsDump.parse(document.getElementsByTagName("h1")), "[ <h1 id=\"qunit-header\"></h1> ]" );
  176. }
  177. });