PageRenderTime 95ms CodeModel.GetById 45ms RepoModel.GetById 1ms app.codeStats 0ms

/test/test.js

https://bitbucket.org/runeh/qunit-ui-refactor
JavaScript | 163 lines | 139 code | 23 blank | 1 comment | 4 complexity | ed54bb15feae72b904e7a42ac84d39c9 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. equals(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. } // end setTimeout tests
  57. if (typeof asyncTest !== 'undefined') {
  58. module("asyncTest");
  59. asyncTest("asyncTest", function() {
  60. expect(2);
  61. ok(true);
  62. setTimeout(function() {
  63. state = "done";
  64. ok(true);
  65. start();
  66. }, 13);
  67. });
  68. asyncTest("asyncTest", 2, function() {
  69. ok(true);
  70. setTimeout(function() {
  71. state = "done";
  72. ok(true);
  73. start();
  74. }, 13);
  75. });
  76. } // end asyncTest tests
  77. module("save scope", {
  78. setup: function() {
  79. this.foo = "bar";
  80. },
  81. teardown: function() {
  82. same(this.foo, "bar");
  83. }
  84. });
  85. test("scope check", function() {
  86. expect(2);
  87. same(this.foo, "bar");
  88. });
  89. module("simple testEnvironment setup", {
  90. foo: "bar",
  91. bugid: "#5311" // example of meta-data
  92. });
  93. test("scope check", function() {
  94. same(this.foo, "bar");
  95. });
  96. test("modify testEnvironment",function() {
  97. this.foo="hamster";
  98. });
  99. test("testEnvironment reset for next test",function() {
  100. same(this.foo, "bar");
  101. });
  102. module("testEnvironment with object", {
  103. options:{
  104. recipe:"soup",
  105. ingredients:["hamster","onions"]
  106. }
  107. });
  108. test("scope check", function() {
  109. same(this.options, {recipe:"soup",ingredients:["hamster","onions"]}) ;
  110. });
  111. test("modify testEnvironment",function() {
  112. // since we do a shallow copy, the testEnvironment can be modified
  113. this.options.ingredients.push("carrots");
  114. });
  115. test("testEnvironment reset for next test",function() {
  116. same(this.options, {recipe:"soup",ingredients:["hamster","onions","carrots"]}, "Is this a bug or a feature? Could do a deep copy") ;
  117. });
  118. module("testEnvironment tests");
  119. function makeurl() {
  120. var testEnv = QUnit.current_testEnvironment;
  121. var url = testEnv.url || 'http://example.com/search';
  122. var q = testEnv.q || 'a search test';
  123. return url + '?q='+encodeURIComponent(q);
  124. }
  125. test("makeurl working",function() {
  126. equals( QUnit.current_testEnvironment, this, 'The current testEnvironment is global');
  127. equals( makeurl(), 'http://example.com/search?q=a%20search%20test', 'makeurl returns a default url if nothing specified in the testEnvironment');
  128. });
  129. module("testEnvironment with makeurl settings",{
  130. url:'http://google.com/',
  131. q:'another_search_test'
  132. });
  133. test("makeurl working with settings from testEnvironment",function() {
  134. equals( makeurl(), 'http://google.com/?q=another_search_test', 'rather than passing arguments, we use test metadata to form the url');
  135. });
  136. test("each test can extend the module testEnvironment", {
  137. q:'hamstersoup'
  138. }, function() {
  139. equals( makeurl(), 'http://google.com/?q=hamstersoup', 'url from module, q from test');
  140. });