unpoly-rails 0.32.0 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of unpoly-rails might be problematic. Click here for more details.

Files changed (232) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +106 -76
  3. data/README.md +8 -5
  4. data/README_RAILS.md +1 -1
  5. data/design/test_rejected_promise.txt +5 -0
  6. data/dist/unpoly-bootstrap3.js +1 -1
  7. data/dist/unpoly-bootstrap3.min.js +1 -1
  8. data/dist/unpoly.js +814 -417
  9. data/dist/unpoly.min.js +3 -3
  10. data/lib/assets/javascripts/unpoly/{browser.js.coffee → browser.coffee} +15 -6
  11. data/lib/assets/javascripts/unpoly/{bus.js.coffee → bus.coffee} +13 -13
  12. data/lib/assets/javascripts/unpoly/dom/extract_cascade.coffee +73 -0
  13. data/lib/assets/javascripts/unpoly/dom/extract_plan.coffee +65 -0
  14. data/lib/assets/javascripts/unpoly/{flow.js.coffee → dom.coffee} +109 -114
  15. data/lib/assets/javascripts/unpoly/{navigation.js.coffee → feedback.coffee} +11 -11
  16. data/lib/assets/javascripts/unpoly/{form.js.coffee → form.coffee} +35 -24
  17. data/lib/assets/javascripts/unpoly/{history.js.coffee → history.coffee} +9 -10
  18. data/lib/assets/javascripts/unpoly/{layout.js.coffee → layout.coffee} +53 -21
  19. data/lib/assets/javascripts/unpoly/{link.js.coffee → link.coffee} +46 -40
  20. data/lib/assets/javascripts/unpoly/{log.js.coffee → log.coffee} +2 -2
  21. data/lib/assets/javascripts/unpoly/{modal.js.coffee → modal.coffee} +17 -14
  22. data/lib/assets/javascripts/unpoly/{motion.js.coffee → motion.coffee} +28 -31
  23. data/lib/assets/javascripts/unpoly/namespace.coffee.erb +10 -0
  24. data/lib/assets/javascripts/unpoly/{popup.js.coffee → popup.coffee} +22 -10
  25. data/lib/assets/javascripts/unpoly/{proxy.js.coffee → proxy.coffee} +34 -12
  26. data/lib/assets/javascripts/unpoly/{rails.js.coffee → rails.coffee} +0 -0
  27. data/lib/assets/javascripts/unpoly/{syntax.js.coffee → syntax.coffee} +32 -21
  28. data/lib/assets/javascripts/unpoly/{toast.js.coffee → toast.coffee} +0 -0
  29. data/lib/assets/javascripts/unpoly/{tooltip.js.coffee → tooltip.coffee} +2 -2
  30. data/lib/assets/javascripts/unpoly/{util.js.coffee → util.coffee} +122 -35
  31. data/lib/assets/javascripts/unpoly-bootstrap3/{form-ext.js.coffee → form-ext.coffee} +0 -0
  32. data/lib/assets/javascripts/unpoly-bootstrap3/{layout-ext.js.coffee → layout-ext.coffee} +0 -0
  33. data/lib/assets/javascripts/unpoly-bootstrap3/{modal-ext.js.coffee → modal-ext.coffee} +0 -0
  34. data/lib/assets/javascripts/unpoly-bootstrap3/{navigation-ext.js.coffee → navigation-ext.coffee} +1 -1
  35. data/lib/assets/javascripts/{unpoly-bootstrap3.js.coffee → unpoly-bootstrap3.coffee} +0 -0
  36. data/lib/assets/javascripts/unpoly.coffee +22 -0
  37. data/lib/assets/stylesheets/unpoly/{close.css.sass → close.sass} +0 -0
  38. data/lib/assets/stylesheets/unpoly/{flow.css.sass → flow.sass} +0 -0
  39. data/lib/assets/stylesheets/unpoly/{link.css.sass → link.sass} +0 -0
  40. data/lib/assets/stylesheets/unpoly/{modal.css.sass → modal.sass} +0 -0
  41. data/lib/assets/stylesheets/unpoly/{popup.css.sass → popup.sass} +0 -0
  42. data/lib/assets/stylesheets/unpoly/{toast.css.sass → toast.sass} +0 -0
  43. data/lib/assets/stylesheets/unpoly/{tooltip.css.sass → tooltip.sass} +0 -0
  44. data/lib/assets/stylesheets/unpoly-bootstrap3/{modal-ext.css.sass → modal-ext.sass} +0 -0
  45. data/lib/assets/stylesheets/{unpoly-bootstrap3.css.sass → unpoly-bootstrap3.sass} +0 -0
  46. data/lib/assets/stylesheets/{unpoly.css.sass → unpoly.sass} +0 -0
  47. data/lib/unpoly/rails/version.rb +1 -1
  48. data/package.json +1 -1
  49. data/spec_app/Gemfile.lock +11 -13
  50. data/spec_app/app/assets/javascripts/jasmine_specs.coffee +1 -1
  51. data/spec_app/app/assets/stylesheets/_helpers.sass +1 -1
  52. data/spec_app/config/initializers/assets.rb +1 -5
  53. data/spec_app/spec/javascripts/up/{flow_spec.js.coffee → dom_spec.js.coffee} +294 -44
  54. data/spec_app/spec/javascripts/up/{navigation_spec.js.coffee → feedback_spec.js.coffee} +2 -2
  55. data/spec_app/spec/javascripts/up/form_spec.js.coffee +1 -0
  56. data/spec_app/spec/javascripts/up/layout_spec.js.coffee +10 -0
  57. data/spec_app/spec/javascripts/up/link_spec.js.coffee +28 -0
  58. data/spec_app/spec/javascripts/up/modal_spec.js.coffee +46 -9
  59. data/spec_app/spec/javascripts/up/motion_spec.js.coffee +32 -2
  60. data/spec_app/spec/javascripts/up/popup_spec.js.coffee +5 -4
  61. data/spec_app/spec/javascripts/up/util_spec.js.coffee +75 -0
  62. data/spec_app/vendor/{assets/bower_components/jasmine-ajax → asset-libs/jasmine-ajax-3.3.1}/.bower.json +0 -0
  63. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.gitignore +6 -0
  64. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.npmignore +10 -0
  65. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.pairs +6 -0
  66. data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.travis.yml +56 -0
  67. data/spec_app/vendor/{assets/bower_components/jasmine-ajax/lib/mock-ajax.js → asset-libs/jasmine-ajax-3.3.1/jasmine-ajax.js} +83 -26
  68. data/spec_app/vendor/{assets/bower_components/jasmine-fixture/dist → asset-libs/jasmine-fixture-1.3.4}/jasmine-fixture.js +13 -13
  69. data/spec_app/vendor/{assets/bower_components/jasmine-jquery → asset-libs/jasmine-jquery-2.1.1}/.bower.json +0 -0
  70. data/spec_app/vendor/{assets/bower_components/jasmine-jquery/lib → asset-libs/jasmine-jquery-2.1.1}/jasmine-jquery.js +0 -0
  71. data/spec_app/vendor/assets/{javascripts/.keep → .keep} +0 -0
  72. metadata +52 -203
  73. data/lib/assets/javascripts/unpoly/module.js.coffee.erb +0 -8
  74. data/lib/assets/javascripts/unpoly.js.coffee +0 -21
  75. data/spec_app/Bowerfile +0 -3
  76. data/spec_app/vendor/assets/.bowerrc +0 -3
  77. data/spec_app/vendor/assets/bower.json +0 -8
  78. data/spec_app/vendor/assets/bower_components/jasmine/.bower.json +0 -50
  79. data/spec_app/vendor/assets/bower_components/jasmine/CONTRIBUTING.md +0 -130
  80. data/spec_app/vendor/assets/bower_components/jasmine/GOALS_2.0.md +0 -64
  81. data/spec_app/vendor/assets/bower_components/jasmine/MANIFEST.in +0 -5
  82. data/spec_app/vendor/assets/bower_components/jasmine/MIT.LICENSE +0 -20
  83. data/spec_app/vendor/assets/bower_components/jasmine/README.md +0 -73
  84. data/spec_app/vendor/assets/bower_components/jasmine/RELEASE.md +0 -73
  85. data/spec_app/vendor/assets/bower_components/jasmine/bower.json +0 -41
  86. data/spec_app/vendor/assets/bower_components/jasmine/images/jasmine-horizontal.png +0 -0
  87. data/spec_app/vendor/assets/bower_components/jasmine/images/jasmine-horizontal.svg +0 -102
  88. data/spec_app/vendor/assets/bower_components/jasmine/images/jasmine_favicon.png +0 -0
  89. data/spec_app/vendor/assets/bower_components/jasmine/lib/console/console.js +0 -190
  90. data/spec_app/vendor/assets/bower_components/jasmine/lib/jasmine-core/boot.js +0 -143
  91. data/spec_app/vendor/assets/bower_components/jasmine/lib/jasmine-core/example/node_example/lib/jasmine_examples/Player.js +0 -24
  92. data/spec_app/vendor/assets/bower_components/jasmine/lib/jasmine-core/example/node_example/lib/jasmine_examples/Song.js +0 -9
  93. data/spec_app/vendor/assets/bower_components/jasmine/lib/jasmine-core/jasmine-html.js +0 -446
  94. data/spec_app/vendor/assets/bower_components/jasmine/lib/jasmine-core/jasmine.css +0 -58
  95. data/spec_app/vendor/assets/bower_components/jasmine/lib/jasmine-core/jasmine.js +0 -3298
  96. data/spec_app/vendor/assets/bower_components/jasmine/lib/jasmine-core/json2.js +0 -489
  97. data/spec_app/vendor/assets/bower_components/jasmine/lib/jasmine-core/node_boot.js +0 -41
  98. data/spec_app/vendor/assets/bower_components/jasmine/lib/jasmine-core.js +0 -37
  99. data/spec_app/vendor/assets/bower_components/jasmine/package.json +0 -34
  100. data/spec_app/vendor/assets/bower_components/jasmine/requirements.txt +0 -1
  101. data/spec_app/vendor/assets/bower_components/jasmine-ajax/MIT.LICENSE +0 -20
  102. data/spec_app/vendor/assets/bower_components/jasmine-ajax/README.markdown +0 -289
  103. data/spec_app/vendor/assets/bower_components/jasmine-ajax/bower.json +0 -35
  104. data/spec_app/vendor/assets/bower_components/jasmine-ajax/package.json +0 -26
  105. data/spec_app/vendor/assets/bower_components/jasmine-ajax/release_notes/2.0.2.md +0 -50
  106. data/spec_app/vendor/assets/bower_components/jasmine-ajax/release_notes/2.99.md +0 -14
  107. data/spec_app/vendor/assets/bower_components/jasmine-ajax/release_notes/3.0.md +0 -28
  108. data/spec_app/vendor/assets/bower_components/jasmine-ajax/release_notes/3.1.0.md +0 -24
  109. data/spec_app/vendor/assets/bower_components/jasmine-ajax/release_notes/3.1.1.md +0 -23
  110. data/spec_app/vendor/assets/bower_components/jasmine-ajax/release_notes/3.2.0.md +0 -20
  111. data/spec_app/vendor/assets/bower_components/jasmine-fixture/.bower.json +0 -27
  112. data/spec_app/vendor/assets/bower_components/jasmine-fixture/.gitignore +0 -8
  113. data/spec_app/vendor/assets/bower_components/jasmine-fixture/.npmignore +0 -8
  114. data/spec_app/vendor/assets/bower_components/jasmine-fixture/LICENSE.txt +0 -24
  115. data/spec_app/vendor/assets/bower_components/jasmine-fixture/README.md +0 -118
  116. data/spec_app/vendor/assets/bower_components/jasmine-fixture/bower.json +0 -17
  117. data/spec_app/vendor/assets/bower_components/jasmine-fixture/dist/jasmine-fixture.min.js +0 -5
  118. data/spec_app/vendor/assets/bower_components/jasmine-fixture/spec-e2e/basic-usage-spec.coffee +0 -14
  119. data/spec_app/vendor/assets/bower_components/jasmine-fixture/spec-e2e/helpers/invariants.coffee +0 -17
  120. data/spec_app/vendor/assets/bower_components/jasmine-fixture/spec-e2e/helpers/spec-within-a-spec.coffee +0 -24
  121. data/spec_app/vendor/assets/bower_components/jasmine-fixture/spec-e2e/helpers/tmp-files.coffee +0 -8
  122. data/spec_app/vendor/assets/bower_components/jasmine-fixture/spec-e2e/support/jasmine1-testem-config.json +0 -11
  123. data/spec_app/vendor/assets/bower_components/jasmine-fixture/spec-e2e/support/jasmine2-testem-config.json +0 -11
  124. data/spec_app/vendor/assets/bower_components/jasmine-fixture/vendor/js/jquery-1.11.0.js +0 -10337
  125. data/spec_app/vendor/assets/bower_components/jasmine-fixture/vendor/js/jquery-1.8.3.js +0 -9472
  126. data/spec_app/vendor/assets/bower_components/jasmine-fixture/vendor/js/jquery-2.1.0.js +0 -9111
  127. data/spec_app/vendor/assets/bower_components/jasmine-jquery/CONTRIBUTING.md +0 -28
  128. data/spec_app/vendor/assets/bower_components/jasmine-jquery/Gruntfile.js +0 -49
  129. data/spec_app/vendor/assets/bower_components/jasmine-jquery/LICENSE +0 -20
  130. data/spec_app/vendor/assets/bower_components/jasmine-jquery/README.md +0 -367
  131. data/spec_app/vendor/assets/bower_components/jasmine-jquery/bower.json +0 -15
  132. data/spec_app/vendor/assets/bower_components/jasmine-jquery/package.json +0 -35
  133. data/spec_app/vendor/assets/bower_components/jasmine-jquery/spec/fixtures/fixture_with_checkbox_with_checked.html +0 -6
  134. data/spec_app/vendor/assets/bower_components/jasmine-jquery/spec/fixtures/fixture_with_javascript.html +0 -1
  135. data/spec_app/vendor/assets/bower_components/jasmine-jquery/spec/fixtures/fixture_with_javascript_block.html +0 -1
  136. data/spec_app/vendor/assets/bower_components/jasmine-jquery/spec/fixtures/javascripts/jasmine_javascript_click.js +0 -1
  137. data/spec_app/vendor/assets/bower_components/jasmine-jquery/spec/fixtures/javascripts/jasmine_javascript_hover.js +0 -1
  138. data/spec_app/vendor/assets/bower_components/jasmine-jquery/spec/fixtures/json/jasmine_json_test.json +0 -1
  139. data/spec_app/vendor/assets/bower_components/jasmine-jquery/spec/fixtures/real_non_mocked_fixture.html +0 -1
  140. data/spec_app/vendor/assets/bower_components/jasmine-jquery/spec/fixtures/real_non_mocked_fixture_style.css +0 -1
  141. data/spec_app/vendor/assets/bower_components/jasmine-jquery/spec/suites/jasmine-jquery-spec.js +0 -1842
  142. data/spec_app/vendor/assets/bower_components/jquery/.bower.json +0 -38
  143. data/spec_app/vendor/assets/bower_components/jquery/MIT-LICENSE.txt +0 -21
  144. data/spec_app/vendor/assets/bower_components/jquery/bower.json +0 -28
  145. data/spec_app/vendor/assets/bower_components/jquery/dist/jquery.js +0 -9210
  146. data/spec_app/vendor/assets/bower_components/jquery/dist/jquery.min.js +0 -5
  147. data/spec_app/vendor/assets/bower_components/jquery/dist/jquery.min.map +0 -1
  148. data/spec_app/vendor/assets/bower_components/jquery/src/ajax/jsonp.js +0 -89
  149. data/spec_app/vendor/assets/bower_components/jquery/src/ajax/load.js +0 -75
  150. data/spec_app/vendor/assets/bower_components/jquery/src/ajax/parseJSON.js +0 -13
  151. data/spec_app/vendor/assets/bower_components/jquery/src/ajax/parseXML.js +0 -28
  152. data/spec_app/vendor/assets/bower_components/jquery/src/ajax/script.js +0 -64
  153. data/spec_app/vendor/assets/bower_components/jquery/src/ajax/var/nonce.js +0 -5
  154. data/spec_app/vendor/assets/bower_components/jquery/src/ajax/var/rquery.js +0 -3
  155. data/spec_app/vendor/assets/bower_components/jquery/src/ajax/xhr.js +0 -136
  156. data/spec_app/vendor/assets/bower_components/jquery/src/ajax.js +0 -786
  157. data/spec_app/vendor/assets/bower_components/jquery/src/attributes/attr.js +0 -141
  158. data/spec_app/vendor/assets/bower_components/jquery/src/attributes/classes.js +0 -158
  159. data/spec_app/vendor/assets/bower_components/jquery/src/attributes/prop.js +0 -94
  160. data/spec_app/vendor/assets/bower_components/jquery/src/attributes/support.js +0 -35
  161. data/spec_app/vendor/assets/bower_components/jquery/src/attributes/val.js +0 -161
  162. data/spec_app/vendor/assets/bower_components/jquery/src/attributes.js +0 -11
  163. data/spec_app/vendor/assets/bower_components/jquery/src/callbacks.js +0 -205
  164. data/spec_app/vendor/assets/bower_components/jquery/src/core/access.js +0 -60
  165. data/spec_app/vendor/assets/bower_components/jquery/src/core/init.js +0 -123
  166. data/spec_app/vendor/assets/bower_components/jquery/src/core/parseHTML.js +0 -39
  167. data/spec_app/vendor/assets/bower_components/jquery/src/core/ready.js +0 -97
  168. data/spec_app/vendor/assets/bower_components/jquery/src/core/var/rsingleTag.js +0 -4
  169. data/spec_app/vendor/assets/bower_components/jquery/src/core.js +0 -502
  170. data/spec_app/vendor/assets/bower_components/jquery/src/css/addGetHookIf.js +0 -22
  171. data/spec_app/vendor/assets/bower_components/jquery/src/css/curCSS.js +0 -57
  172. data/spec_app/vendor/assets/bower_components/jquery/src/css/defaultDisplay.js +0 -70
  173. data/spec_app/vendor/assets/bower_components/jquery/src/css/hiddenVisibleSelectors.js +0 -15
  174. data/spec_app/vendor/assets/bower_components/jquery/src/css/support.js +0 -96
  175. data/spec_app/vendor/assets/bower_components/jquery/src/css/swap.js +0 -28
  176. data/spec_app/vendor/assets/bower_components/jquery/src/css/var/cssExpand.js +0 -3
  177. data/spec_app/vendor/assets/bower_components/jquery/src/css/var/getStyles.js +0 -12
  178. data/spec_app/vendor/assets/bower_components/jquery/src/css/var/isHidden.js +0 -13
  179. data/spec_app/vendor/assets/bower_components/jquery/src/css/var/rmargin.js +0 -3
  180. data/spec_app/vendor/assets/bower_components/jquery/src/css/var/rnumnonpx.js +0 -5
  181. data/spec_app/vendor/assets/bower_components/jquery/src/css.js +0 -450
  182. data/spec_app/vendor/assets/bower_components/jquery/src/data/Data.js +0 -181
  183. data/spec_app/vendor/assets/bower_components/jquery/src/data/accepts.js +0 -20
  184. data/spec_app/vendor/assets/bower_components/jquery/src/data/var/data_priv.js +0 -5
  185. data/spec_app/vendor/assets/bower_components/jquery/src/data/var/data_user.js +0 -5
  186. data/spec_app/vendor/assets/bower_components/jquery/src/data.js +0 -178
  187. data/spec_app/vendor/assets/bower_components/jquery/src/deferred.js +0 -149
  188. data/spec_app/vendor/assets/bower_components/jquery/src/deprecated.js +0 -13
  189. data/spec_app/vendor/assets/bower_components/jquery/src/dimensions.js +0 -50
  190. data/spec_app/vendor/assets/bower_components/jquery/src/effects/Tween.js +0 -114
  191. data/spec_app/vendor/assets/bower_components/jquery/src/effects/animatedSelector.js +0 -13
  192. data/spec_app/vendor/assets/bower_components/jquery/src/effects.js +0 -648
  193. data/spec_app/vendor/assets/bower_components/jquery/src/event/ajax.js +0 -13
  194. data/spec_app/vendor/assets/bower_components/jquery/src/event/alias.js +0 -39
  195. data/spec_app/vendor/assets/bower_components/jquery/src/event/support.js +0 -9
  196. data/spec_app/vendor/assets/bower_components/jquery/src/event.js +0 -868
  197. data/spec_app/vendor/assets/bower_components/jquery/src/exports/amd.js +0 -24
  198. data/spec_app/vendor/assets/bower_components/jquery/src/exports/global.js +0 -32
  199. data/spec_app/vendor/assets/bower_components/jquery/src/intro.js +0 -44
  200. data/spec_app/vendor/assets/bower_components/jquery/src/jquery.js +0 -37
  201. data/spec_app/vendor/assets/bower_components/jquery/src/manipulation/_evalUrl.js +0 -18
  202. data/spec_app/vendor/assets/bower_components/jquery/src/manipulation/support.js +0 -32
  203. data/spec_app/vendor/assets/bower_components/jquery/src/manipulation/var/rcheckableType.js +0 -3
  204. data/spec_app/vendor/assets/bower_components/jquery/src/manipulation.js +0 -580
  205. data/spec_app/vendor/assets/bower_components/jquery/src/offset.js +0 -207
  206. data/spec_app/vendor/assets/bower_components/jquery/src/outro.js +0 -1
  207. data/spec_app/vendor/assets/bower_components/jquery/src/queue/delay.js +0 -22
  208. data/spec_app/vendor/assets/bower_components/jquery/src/queue.js +0 -142
  209. data/spec_app/vendor/assets/bower_components/jquery/src/selector-native.js +0 -172
  210. data/spec_app/vendor/assets/bower_components/jquery/src/selector-sizzle.js +0 -14
  211. data/spec_app/vendor/assets/bower_components/jquery/src/selector.js +0 -1
  212. data/spec_app/vendor/assets/bower_components/jquery/src/serialize.js +0 -111
  213. data/spec_app/vendor/assets/bower_components/jquery/src/sizzle/dist/sizzle.js +0 -2067
  214. data/spec_app/vendor/assets/bower_components/jquery/src/sizzle/dist/sizzle.min.js +0 -3
  215. data/spec_app/vendor/assets/bower_components/jquery/src/sizzle/dist/sizzle.min.map +0 -1
  216. data/spec_app/vendor/assets/bower_components/jquery/src/traversing/findFilter.js +0 -100
  217. data/spec_app/vendor/assets/bower_components/jquery/src/traversing/var/rneedsContext.js +0 -6
  218. data/spec_app/vendor/assets/bower_components/jquery/src/traversing.js +0 -199
  219. data/spec_app/vendor/assets/bower_components/jquery/src/var/arr.js +0 -3
  220. data/spec_app/vendor/assets/bower_components/jquery/src/var/class2type.js +0 -4
  221. data/spec_app/vendor/assets/bower_components/jquery/src/var/concat.js +0 -5
  222. data/spec_app/vendor/assets/bower_components/jquery/src/var/hasOwn.js +0 -5
  223. data/spec_app/vendor/assets/bower_components/jquery/src/var/indexOf.js +0 -5
  224. data/spec_app/vendor/assets/bower_components/jquery/src/var/pnum.js +0 -3
  225. data/spec_app/vendor/assets/bower_components/jquery/src/var/push.js +0 -5
  226. data/spec_app/vendor/assets/bower_components/jquery/src/var/rnotwhite.js +0 -3
  227. data/spec_app/vendor/assets/bower_components/jquery/src/var/slice.js +0 -5
  228. data/spec_app/vendor/assets/bower_components/jquery/src/var/strundefined.js +0 -3
  229. data/spec_app/vendor/assets/bower_components/jquery/src/var/support.js +0 -4
  230. data/spec_app/vendor/assets/bower_components/jquery/src/var/toString.js +0 -5
  231. data/spec_app/vendor/assets/bower_components/jquery/src/wrap.js +0 -79
  232. data/spec_app/vendor/assets/stylesheets/.keep +0 -0
@@ -1,1842 +0,0 @@
1
- describe("jasmine.Fixtures", function () {
2
- var ajaxData = 'some ajax data'
3
- var fixtureUrl = 'some_url'
4
- var anotherFixtureUrl = 'another_url'
5
- var fixturesContainer = function () {
6
- return $('#' + jasmine.getFixtures().containerId)
7
- }
8
- var appendFixturesContainerToDom = function () {
9
- $('body').append('<div id="' + jasmine.getFixtures().containerId + '">old content</div>')
10
- }
11
-
12
- beforeEach(function () {
13
- jasmine.getFixtures().clearCache()
14
- spyOn(jasmine.Fixtures.prototype, 'loadFixtureIntoCache_').and.callFake(function (relativeUrl){
15
- this.fixturesCache_[relativeUrl] = ajaxData
16
- })
17
- })
18
-
19
- describe("default initial config values", function () {
20
- it("should set 'jasmine-fixtures' as the default container id", function () {
21
- expect(jasmine.getFixtures().containerId).toEqual('jasmine-fixtures')
22
- })
23
-
24
- it("should set 'spec/javascripts/fixtures' as the default fixtures path", function () {
25
- expect(jasmine.getFixtures().fixturesPath).toEqual('spec/javascripts/fixtures')
26
- })
27
- })
28
-
29
- describe("cache", function () {
30
- describe("clearCache", function () {
31
- it("should clear cache and in effect force subsequent AJAX call", function () {
32
- jasmine.getFixtures().read(fixtureUrl)
33
- jasmine.getFixtures().clearCache()
34
- jasmine.getFixtures().read(fixtureUrl)
35
- expect(jasmine.Fixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(2)
36
- })
37
- })
38
-
39
- it("first-time read should go through AJAX", function () {
40
- jasmine.getFixtures().read(fixtureUrl)
41
- expect(jasmine.Fixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(1)
42
- })
43
-
44
- it("subsequent read from the same URL should go from cache", function () {
45
- jasmine.getFixtures().read(fixtureUrl, fixtureUrl)
46
- expect(jasmine.Fixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(1)
47
- })
48
- })
49
-
50
- describe("read", function () {
51
- it("should return fixture HTML", function () {
52
- var html = jasmine.getFixtures().read(fixtureUrl)
53
- expect(html).toEqual(ajaxData)
54
- })
55
-
56
- it("should return duplicated HTML of a fixture when its url is provided twice in a single call", function () {
57
- var html = jasmine.getFixtures().read(fixtureUrl, fixtureUrl)
58
- expect(html).toEqual(ajaxData + ajaxData)
59
- })
60
-
61
- it("should return merged HTML of two fixtures when two different urls are provided in a single call", function () {
62
- var html = jasmine.getFixtures().read(fixtureUrl, anotherFixtureUrl)
63
- expect(html).toEqual(ajaxData + ajaxData)
64
- })
65
-
66
- it("should have shortcut global method readFixtures", function () {
67
- var html = readFixtures(fixtureUrl, anotherFixtureUrl)
68
- expect(html).toEqual(ajaxData + ajaxData)
69
- })
70
-
71
- it("should use the configured fixtures path concatenating it to the requested url (without concatenating a slash if it already has an ending one)", function () {
72
- jasmine.getFixtures().fixturesPath = 'a path ending with slash/'
73
- expect(jasmine.getFixtures().makeFixtureUrl_(fixtureUrl)).toEqual('a path ending with slash/'+fixtureUrl)
74
- })
75
-
76
- it("should use the configured fixtures path concatenating it to the requested url (concatenating a slash if it doesn't have an ending one)", function () {
77
- jasmine.getFixtures().fixturesPath = 'a path without an ending slash'
78
- expect(jasmine.getFixtures().makeFixtureUrl_(fixtureUrl)).toEqual('a path without an ending slash/'+fixtureUrl)
79
- })
80
- })
81
-
82
- describe("load", function () {
83
- it("should insert fixture HTML into container", function () {
84
- jasmine.getFixtures().load(fixtureUrl)
85
- expect(fixturesContainer().html()).toEqual(ajaxData)
86
- })
87
-
88
- it("should insert duplicated fixture HTML into container when the same url is provided twice in a single call", function () {
89
- jasmine.getFixtures().load(fixtureUrl, fixtureUrl)
90
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
91
- })
92
-
93
- it("should insert merged HTML of two fixtures into container when two different urls are provided in a single call", function () {
94
- jasmine.getFixtures().load(fixtureUrl, anotherFixtureUrl)
95
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
96
- })
97
-
98
- it("should have shortcut global method loadFixtures", function () {
99
- loadFixtures(fixtureUrl, anotherFixtureUrl)
100
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
101
- })
102
-
103
- describe("when fixture container does not exist", function () {
104
- it("should automatically create fixtures container and append it to DOM", function () {
105
- jasmine.getFixtures().load(fixtureUrl)
106
- expect(fixturesContainer().size()).toEqual(1)
107
- })
108
- })
109
-
110
- describe("when fixture container exists", function () {
111
- beforeEach(function () {
112
- appendFixturesContainerToDom()
113
- })
114
-
115
- it("should replace it with new content", function () {
116
- jasmine.getFixtures().load(fixtureUrl)
117
- expect(fixturesContainer().html()).toEqual(ajaxData)
118
- })
119
- })
120
-
121
- describe("when fixture contains an inline <script> tag", function (){
122
- beforeEach(function (){
123
- ajaxData = "<div><a id=\"anchor_01\"></a><script>$(function (){ $('#anchor_01').addClass('foo')});</script></div>"
124
- })
125
-
126
- it("should execute the inline javascript after the fixture has been inserted into the body", function (){
127
- jasmine.getFixtures().load(fixtureUrl)
128
- expect($("#anchor_01")).toHaveClass('foo')
129
- })
130
- })
131
- })
132
-
133
- describe("appendLoad", function () {
134
- beforeEach(function (){
135
- ajaxData = 'some ajax data'
136
- })
137
-
138
- it("should insert fixture HTML into container", function () {
139
- jasmine.getFixtures().appendLoad(fixtureUrl)
140
- expect(fixturesContainer().html()).toEqual(ajaxData)
141
- })
142
-
143
- it("should insert duplicated fixture HTML into container when the same url is provided twice in a single call", function () {
144
- jasmine.getFixtures().appendLoad(fixtureUrl, fixtureUrl)
145
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
146
- })
147
-
148
- it("should insert merged HTML of two fixtures into container when two different urls are provided in a single call", function () {
149
- jasmine.getFixtures().appendLoad(fixtureUrl, anotherFixtureUrl)
150
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
151
- })
152
-
153
- it("should have shortcut global method loadFixtures", function () {
154
- appendLoadFixtures(fixtureUrl, anotherFixtureUrl)
155
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
156
- })
157
-
158
- it("should automatically create fixtures container and append it to DOM", function () {
159
- jasmine.getFixtures().appendLoad(fixtureUrl)
160
- expect(fixturesContainer().size()).toEqual(1)
161
- })
162
-
163
- describe("with a prexisting fixture",function (){
164
- beforeEach(function () {
165
- jasmine.getFixtures().appendLoad(fixtureUrl)
166
- })
167
-
168
- it("should add new content", function () {
169
- jasmine.getFixtures().appendLoad(fixtureUrl)
170
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
171
- })
172
-
173
- it("should not add a new fixture container", function (){
174
- jasmine.getFixtures().appendLoad(fixtureUrl)
175
- expect(fixturesContainer().size()).toEqual(1)
176
- })
177
- })
178
-
179
- describe("when fixture contains an inline <script> tag", function (){
180
- beforeEach(function (){
181
- ajaxData = "<div><a id=\"anchor_01\"></a><script>$(function (){ $('#anchor_01').addClass('foo')});</script></div>"
182
- })
183
-
184
- it("should execute the inline javascript after the fixture has been inserted into the body", function (){
185
- jasmine.getFixtures().appendLoad(fixtureUrl)
186
- expect($("#anchor_01")).toHaveClass('foo')
187
- })
188
- })
189
- })
190
-
191
- describe("preload", function () {
192
- describe("read after preload", function () {
193
- it("should go from cache", function () {
194
- jasmine.getFixtures().preload(fixtureUrl, anotherFixtureUrl)
195
- jasmine.getFixtures().read(fixtureUrl, anotherFixtureUrl)
196
- expect(jasmine.Fixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(2)
197
- })
198
-
199
- it("should return correct HTMLs", function () {
200
- jasmine.getFixtures().preload(fixtureUrl, anotherFixtureUrl)
201
- var html = jasmine.getFixtures().read(fixtureUrl, anotherFixtureUrl)
202
- expect(html).toEqual(ajaxData + ajaxData)
203
- })
204
- })
205
-
206
- it("should not preload the same fixture twice", function () {
207
- jasmine.getFixtures().preload(fixtureUrl, fixtureUrl)
208
- expect(jasmine.Fixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(1)
209
- })
210
-
211
- it("should have shortcut global method preloadFixtures", function () {
212
- preloadFixtures(fixtureUrl, anotherFixtureUrl)
213
- jasmine.getFixtures().read(fixtureUrl, anotherFixtureUrl)
214
- expect(jasmine.Fixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(2)
215
- })
216
- })
217
-
218
- describe("set", function () {
219
- var html = '<div>some HTML</div>'
220
-
221
- it("should insert HTML into container", function () {
222
- jasmine.getFixtures().set(html)
223
- expect(fixturesContainer().html()).toEqual(jasmine.jQuery.browserTagCaseIndependentHtml(html))
224
- })
225
-
226
- it("should insert jQuery element into container", function () {
227
- jasmine.getFixtures().set($(html))
228
- expect(fixturesContainer().html()).toEqual(jasmine.jQuery.browserTagCaseIndependentHtml(html))
229
- })
230
-
231
- describe("when fixture container does not exist", function () {
232
- it("should automatically create fixtures container and append it to DOM", function () {
233
- jasmine.getFixtures().set(html)
234
- expect(fixturesContainer().size()).toEqual(1)
235
- })
236
-
237
- it("should return the fixture container", function () {
238
- var container = jasmine.getFixtures().set(html)
239
- expect(container).toExist()
240
- expect(container[0]).toEqual(fixturesContainer()[0])
241
- })
242
- })
243
-
244
- describe("when fixture container exists", function () {
245
- beforeEach(function () {
246
- appendFixturesContainerToDom()
247
- })
248
-
249
- it("should replace it with new content", function () {
250
- jasmine.getFixtures().set(html)
251
- expect(fixturesContainer().html()).toEqual(jasmine.jQuery.browserTagCaseIndependentHtml(html))
252
- })
253
-
254
- it("should return the fixture container", function (){
255
- var container = jasmine.getFixtures().set(html)
256
- expect(container).toExist()
257
- expect(container[0]).toEqual(fixturesContainer()[0])
258
- })
259
- })
260
- })
261
-
262
- describe("setFixtures", function () {
263
- var html = '<div>some HTML</div>'
264
-
265
- it("should be a shortcut global method", function () {
266
- setFixtures(html)
267
- expect(fixturesContainer().html()).toEqual(jasmine.jQuery.browserTagCaseIndependentHtml(html))
268
- })
269
-
270
- it("should return the fixture container", function () {
271
- var container = setFixtures(html)
272
- expect(container).toExist()
273
- expect(container[0]).toEqual(fixturesContainer()[0])
274
- })
275
- })
276
-
277
- describe("appendSet",function (){
278
- var html = '<div>some HTML</div>'
279
- it("should insert HTML into container", function () {
280
- jasmine.getFixtures().appendSet(html)
281
- expect(fixturesContainer().html()).toEqual(jasmine.jQuery.browserTagCaseIndependentHtml(html))
282
- })
283
-
284
- it("should insert jQuery element into container", function () {
285
- jasmine.getFixtures().appendSet($(html))
286
- expect(fixturesContainer().html()).toEqual(jasmine.jQuery.browserTagCaseIndependentHtml(html))
287
- })
288
-
289
- it("should have shortcut global method setFixtures", function () {
290
- appendSetFixtures(html)
291
- expect(fixturesContainer().html()).toEqual(jasmine.jQuery.browserTagCaseIndependentHtml(html))
292
- })
293
-
294
- describe("when fixture container does not exist", function () {
295
- it("should automatically create fixtures container and append it to DOM", function () {
296
- jasmine.getFixtures().appendSet(html)
297
- expect(fixturesContainer().size()).toEqual(1)
298
- })
299
- })
300
-
301
- describe("when fixture container exists", function () {
302
- beforeEach(function () {
303
- jasmine.getFixtures().appendSet(html)
304
- })
305
-
306
- it("should add new content", function () {
307
- jasmine.getFixtures().appendSet(html)
308
- expect(fixturesContainer().html()).toEqual(jasmine.jQuery.browserTagCaseIndependentHtml(html)+jasmine.jQuery.browserTagCaseIndependentHtml(html))
309
- })
310
- })
311
- })
312
-
313
- describe("sandbox", function () {
314
- describe("with no attributes parameter specified", function () {
315
- it("should create DIV with id #sandbox", function () {
316
- expect(jasmine.getFixtures().sandbox().html()).toEqual($('<div id="sandbox" />').html())
317
- })
318
- })
319
-
320
- describe("with attributes parameter specified", function () {
321
- it("should create DIV with attributes", function () {
322
- var attributes = {
323
- attr1: 'attr1 value',
324
- attr2: 'attr2 value'
325
- }
326
- var element = $(jasmine.getFixtures().sandbox(attributes))
327
-
328
- expect(element.attr('attr1')).toEqual(attributes.attr1)
329
- expect(element.attr('attr2')).toEqual(attributes.attr2)
330
- })
331
-
332
- it("should be able to override id by setting it as attribute", function () {
333
- var idOverride = 'overridden'
334
- var element = $(jasmine.getFixtures().sandbox({id: idOverride}))
335
- expect(element.attr('id')).toEqual(idOverride)
336
- })
337
- })
338
-
339
- it("should have shortcut global method sandbox", function () {
340
- var attributes = {
341
- id: 'overridden'
342
- }
343
- var element = $(sandbox(attributes))
344
- expect(element.attr('id')).toEqual(attributes.id)
345
- })
346
- })
347
-
348
- describe("cleanUp", function () {
349
- it("should remove fixtures container from DOM", function () {
350
- appendFixturesContainerToDom()
351
- jasmine.getFixtures().cleanUp()
352
- expect(fixturesContainer().size()).toEqual(0)
353
- })
354
- })
355
-
356
- // WARNING: this block requires its two tests to be invoked in order!
357
- // (Really ugly solution, but unavoidable in this specific case)
358
- describe("automatic DOM clean-up between tests", function () {
359
- // WARNING: this test must be invoked first (before 'SECOND TEST')!
360
- it("FIRST TEST: should pollute the DOM", function () {
361
- appendFixturesContainerToDom()
362
- })
363
-
364
- // WARNING: this test must be invoked second (after 'FIRST TEST')!
365
- it("SECOND TEST: should see the DOM in a blank state", function () {
366
- expect(fixturesContainer().size()).toEqual(0)
367
- })
368
- })
369
- })
370
-
371
- describe("jasmine.Fixtures using real AJAX call", function () {
372
- var defaultFixturesPath
373
-
374
- beforeEach(function () {
375
- defaultFixturesPath = jasmine.getFixtures().fixturesPath
376
- jasmine.getFixtures().fixturesPath = 'spec/fixtures'
377
- })
378
-
379
- afterEach(function () {
380
- jasmine.getFixtures().fixturesPath = defaultFixturesPath
381
- })
382
-
383
- describe("when fixture file exists", function () {
384
- var fixtureUrl = "real_non_mocked_fixture.html"
385
-
386
- it("should load content of fixture file", function () {
387
- var fixtureContent = jasmine.getFixtures().read(fixtureUrl)
388
- expect(fixtureContent).toEqual('<div id="real_non_mocked_fixture"></div>')
389
- })
390
- })
391
-
392
- describe("when fixture file does not exist", function () {
393
- var fixtureUrl = "not_existing_fixture"
394
-
395
- it("should throw an exception", function () {
396
- expect(function () {
397
- jasmine.getFixtures().read(fixtureUrl)
398
- }).toThrow()
399
- })
400
- })
401
-
402
- describe("when fixture contains an <script src='to/your/source'> tag", function () {
403
- var fixtureUrl = "fixture_with_javascript.html"
404
-
405
- it("should load content of fixture file and javascript and bind events", function () {
406
- jasmine.getFixtures().load(fixtureUrl)
407
- $('#anchor_01').click()
408
- expect($("#anchor_01")).toHaveClass('foo')
409
- })
410
-
411
- it("should load multiple javascripts and bind events in fixture", function () {
412
- jasmine.getFixtures().load(fixtureUrl)
413
- $('#anchor_01').click()
414
- $('#anchor_01').trigger('hover')
415
- expect($("#anchor_01")).toHaveClass('foo')
416
- expect($("#anchor_01")).toHaveClass('bar')
417
- })
418
- })
419
-
420
- describe("when fixture contains a <script> tag without a src attribute", function () {
421
- var fixtureUrl = "fixture_with_javascript_block.html"
422
-
423
- it("should load the fixture and ignore the script tag", function () {
424
- jasmine.getFixtures().load(fixtureUrl)
425
- expect($("#anchor_01").length).toBe(1)
426
- })
427
- })
428
-
429
- describe("When the fixture contains a HTML 5 style checked checkbox", function () {
430
- var fixtureUrl = "fixture_with_checkbox_with_checked.html"
431
-
432
- it("Then the fixture is loaded successfully", function () {
433
- jasmine.getFixtures().load(fixtureUrl)
434
- expect('#' + jasmine.getFixtures().containerId).toContainElement('#checked-box')
435
- })
436
- })
437
- })
438
-
439
- describe("jQuery matcher", function () {
440
- describe("when invoked multiple times on the same fixture", function () {
441
- it("should not reset fixture after first call", function () {
442
- setFixtures(sandbox())
443
- expect($('#sandbox')).toExist()
444
- expect($('#sandbox')).toExist()
445
- })
446
- })
447
-
448
- describe("toHaveClass", function () {
449
- var className = "some-class"
450
-
451
- it("should pass when class found", function () {
452
- setFixtures(sandbox({'class': className}))
453
- expect($('#sandbox')).toHaveClass(className)
454
- expect($('#sandbox').get(0)).toHaveClass(className)
455
- })
456
-
457
- it("should pass negated when class not found", function () {
458
- setFixtures(sandbox())
459
- expect($('#sandbox')).not.toHaveClass(className)
460
- expect($('#sandbox').get(0)).not.toHaveClass(className)
461
- })
462
-
463
- it("should not crash when documentElement provided", function (){
464
- var doc = $(document.documentElement).addClass(className)
465
- expect(doc).toHaveClass(className)
466
- doc.removeClass(className)
467
- expect(doc).not.toHaveClass(className)
468
- })
469
- })
470
-
471
- describe("toHaveAttr", function () {
472
- var attributeName = 'attr1'
473
- var attributeValue = 'attr1 value'
474
- var wrongAttributeName = 'wrongName'
475
- var wrongAttributeValue = 'wrong value'
476
-
477
- beforeEach(function () {
478
- var attributes = {}
479
- attributes[attributeName] = attributeValue
480
- setFixtures(sandbox(attributes))
481
- })
482
-
483
- describe("when only attribute name is provided", function () {
484
- it("should pass if element has matching attribute", function () {
485
- expect($('#sandbox')).toHaveAttr(attributeName)
486
- expect($('#sandbox').get(0)).toHaveAttr(attributeName)
487
- })
488
-
489
- it("should pass negated if element has no matching attribute", function () {
490
- expect($('#sandbox')).not.toHaveAttr(wrongAttributeName)
491
- expect($('#sandbox').get(0)).not.toHaveAttr(wrongAttributeName)
492
- })
493
- })
494
-
495
- describe("when both attribute name and value are provided", function () {
496
- it("should pass if element has matching attribute with matching value", function () {
497
- expect($('#sandbox')).toHaveAttr(attributeName, attributeValue)
498
- expect($('#sandbox').get(0)).toHaveAttr(attributeName, attributeValue)
499
- })
500
-
501
- it("should pass negated if element has matching attribute but with wrong value", function () {
502
- expect($('#sandbox')).not.toHaveAttr(attributeName, wrongAttributeValue)
503
- expect($('#sandbox').get(0)).not.toHaveAttr(attributeName, wrongAttributeValue)
504
- })
505
-
506
- it("should pass negated if element has no matching attribute", function () {
507
- expect($('#sandbox')).not.toHaveAttr(wrongAttributeName, attributeValue)
508
- expect($('#sandbox').get(0)).not.toHaveAttr(wrongAttributeName, attributeValue)
509
- })
510
- })
511
- })
512
-
513
- describe("toHaveProp", function () {
514
- var propertyName = 'prop1'
515
- var propertyValue = 'prop1 value'
516
- var wrongPropertyName = 'wrongName'
517
- var wrongPropertyValue = 'wrong value'
518
-
519
- beforeEach(function () {
520
- setFixtures(sandbox())
521
- var element = $('#sandbox')[0]
522
- element[propertyName] = propertyValue
523
- })
524
-
525
- describe("when only property name is provided", function () {
526
- it("should pass if element has matching property", function () {
527
- expect($('#sandbox')).toHaveProp(propertyName)
528
- })
529
-
530
- it("should pass negated if element has no matching property", function () {
531
- expect($('#sandbox')).not.toHaveProp(wrongPropertyName)
532
- })
533
- })
534
-
535
- describe("when both property name and value are provided", function () {
536
- it("should pass if element has matching property with matching value", function () {
537
- expect($('#sandbox')).toHaveProp(propertyName, propertyValue)
538
- })
539
-
540
- it("should pass negated if element has matching property but with wrong value", function () {
541
- expect($('#sandbox')).not.toHaveProp(propertyName, wrongPropertyValue)
542
- })
543
-
544
- it("should pass negated if element has no matching property", function () {
545
- expect($('#sandbox')).not.toHaveProp(wrongPropertyName, propertyValue)
546
- })
547
- })
548
- })
549
-
550
- describe("toHaveCss", function (){
551
- beforeEach(function (){
552
- setFixtures(sandbox())
553
- })
554
-
555
- it("should pass if the element has matching css", function (){
556
- $("#sandbox").css("display", "none")
557
- $("#sandbox").css("margin-left", "10px")
558
- expect($("#sandbox")).toHaveCss({display: "none", "margin-left": "10px"})
559
- })
560
-
561
- it("should be able to check a subset of element's css", function (){
562
- $("#sandbox").css("display", "none")
563
- $("#sandbox").css("margin-left", "10px")
564
- expect($("#sandbox")).toHaveCss({"margin-left": "10px"})
565
- })
566
-
567
- it("should fail if the element doesn't have matching css", function (){
568
- $("#sandbox").css("display", "none")
569
- $("#sandbox").css("margin-left", "20px")
570
- expect($("#sandbox")).not.toHaveCss({display: "none", "margin-left": "10px"})
571
- })
572
-
573
- it("should pass if the css property is auto and you check that property for auto", function (){
574
- $("#sandbox").css("height", "auto");
575
- $("#sandbox").css("margin-left", "auto");
576
- $("#sandbox").css("display", "none");
577
- expect($("#sandbox")).toHaveCss({height: 'auto', 'margin-left': "auto", display: "none"});
578
- })
579
- })
580
-
581
- describe("toHaveId", function () {
582
- beforeEach(function () {
583
- setFixtures(sandbox())
584
- })
585
-
586
- it("should pass if id attribute matches expectation", function () {
587
- expect($('#sandbox')).toHaveId('sandbox')
588
- expect($('#sandbox').get(0)).toHaveId('sandbox')
589
- })
590
-
591
- it("should pass negated if id attribute does not match expectation", function () {
592
- expect($('#sandbox')).not.toHaveId('wrongId')
593
- expect($('#sandbox').get(0)).not.toHaveId('wrongId')
594
- })
595
-
596
- it("should pass negated if id attribute is not present", function () {
597
- expect($('<div />')).not.toHaveId('sandbox')
598
- expect($('<div />').get(0)).not.toHaveId('sandbox')
599
- })
600
- })
601
-
602
- describe("toHaveHtml", function () {
603
- var html = '<div>some text</div>'
604
- var wrongHtml = '<span>some text</span>'
605
- var element
606
-
607
- beforeEach(function () {
608
- element = $('<div/>').append(html)
609
- })
610
-
611
- it("should pass when html matches", function () {
612
- expect(element).toHaveHtml(html)
613
- expect(element.get(0)).toHaveHtml(html)
614
- })
615
-
616
- it("should pass negated when html does not match", function () {
617
- expect(element).not.toHaveHtml(wrongHtml)
618
- expect(element.get(0)).not.toHaveHtml(wrongHtml)
619
- })
620
- })
621
-
622
- describe("toContainHtml", function (){
623
- beforeEach(function (){
624
- setFixtures(sandbox())
625
- })
626
-
627
- it("should pass when the element contains given html", function (){
628
- $("#sandbox").html("<div><ul></ul><h1>foo</h1></div>")
629
- expect($("#sandbox")).toContainHtml("<ul></ul>")
630
- })
631
-
632
- it("should fail when the element doesn't contain given html", function (){
633
- $("#sandbox").html("<div><h1>foo</h1></div>")
634
- expect($("#sandbox")).not.toContainHtml("<ul></ul>")
635
- })
636
- })
637
-
638
- describe("toHaveText", function () {
639
- var text = 'some text'
640
- var wrongText = 'some other text'
641
- var element
642
-
643
- beforeEach(function () {
644
- element = $('<div/>').append(text)
645
- })
646
-
647
- it("should pass when text matches", function () {
648
- expect(element).toHaveText(text)
649
- expect(element.get(0)).toHaveText(text)
650
- })
651
-
652
- it("should ignore surrounding whitespace in the element", function () {
653
- element = $('<div>\n' + text + '\n</div>')
654
- expect(element).toHaveText(text)
655
- expect(element.get(0)).toHaveText(text)
656
- })
657
-
658
- it("should match with surrounding whitespace in the input", function () {
659
- element = $('<div>\n' + text + '\n</div>')
660
- expect(element).toHaveText('\n' + text + '\n')
661
- expect(element.get(0)).toHaveText(text)
662
- })
663
-
664
- it("should pass negated when text does not match", function () {
665
- expect(element).not.toHaveText(wrongText)
666
- expect(element.get(0)).not.toHaveText(wrongText)
667
- })
668
-
669
- it('should pass when text matches a regex', function () {
670
- expect(element).toHaveText(/some/)
671
- expect(element.get(0)).toHaveText(/some/)
672
- })
673
-
674
- it('should pass negated when text does not match a regex', function () {
675
- expect(element).not.toHaveText(/other/)
676
- expect(element.get(0)).not.toHaveText(/other/)
677
- })
678
- })
679
-
680
- describe("toContainText", function () {
681
- var text = 'some pretty long bits of text'
682
- var textPart = 'pret'
683
- var wrongText = 'some other text'
684
- var element
685
-
686
- beforeEach(function () {
687
- element = $('<div/>').append(text)
688
- })
689
-
690
- it("should pass when text contains text part", function () {
691
- expect(element).toContainText(textPart)
692
- expect(element.get(0)).toContainText(textPart)
693
- })
694
-
695
- it("should pass negated when text does not match", function () {
696
- expect(element).not.toContainText(wrongText)
697
- expect(element.get(0)).not.toContainText(wrongText)
698
- })
699
-
700
- it('should pass when text matches a regex', function () {
701
- expect(element).toContainText(/some/)
702
- expect(element.get(0)).toContainText(/some/)
703
- })
704
-
705
- it('should pass negated when text does not match a regex', function () {
706
- expect(element).not.toContainText(/other/)
707
- expect(element.get(0)).not.toContainText(/other/)
708
- })
709
- })
710
-
711
- describe("toHaveValue", function () {
712
- var value = 'some value'
713
- var differentValue = 'different value'
714
-
715
- beforeEach(function () {
716
- setFixtures($('<input id="sandbox" type="text" />').val(value))
717
- })
718
-
719
- it("should pass if value matches expectation", function () {
720
- expect($('#sandbox')).toHaveValue(value)
721
- expect($('#sandbox').get(0)).toHaveValue(value)
722
- })
723
-
724
- it("should pass negated if value does not match expectation", function () {
725
- expect($('#sandbox')).not.toHaveValue(differentValue)
726
- expect($('#sandbox').get(0)).not.toHaveValue(differentValue)
727
- })
728
-
729
- it("should pass negated if value attribute is not present", function () {
730
- expect(sandbox()).not.toHaveValue(value)
731
- expect(sandbox().get(0)).not.toHaveValue(value)
732
- })
733
-
734
- it("should not coerce types", function (){
735
- setFixtures($('<input id="sandbox" type="text" />').val(""))
736
- expect($('#sandbox')).not.toHaveValue(0)
737
- })
738
- })
739
-
740
- describe("toHaveData", function () {
741
- var key = 'some key'
742
- var value = 'some value'
743
- var wrongKey = 'wrong key'
744
- var wrongValue = 'wrong value'
745
-
746
- beforeEach(function () {
747
- setFixtures(sandbox().data(key, value))
748
- })
749
-
750
- describe("when only key is provided", function () {
751
- it("should pass if element has matching data key", function () {
752
- expect($('#sandbox')).toHaveData(key)
753
- expect($('#sandbox').get(0)).toHaveData(key)
754
- })
755
-
756
- it("should pass negated if element has no matching data key", function () {
757
- expect($('#sandbox')).not.toHaveData(wrongKey)
758
- expect($('#sandbox').get(0)).not.toHaveData(wrongKey)
759
- })
760
- })
761
-
762
- describe("when both key and value are provided", function () {
763
- it("should pass if element has matching key with matching value", function () {
764
- expect($('#sandbox')).toHaveData(key, value)
765
- expect($('#sandbox').get(0)).toHaveData(key, value)
766
- })
767
-
768
- it("should pass negated if element has matching key but with wrong value", function () {
769
- expect($('#sandbox')).not.toHaveData(key, wrongValue)
770
- expect($('#sandbox').get(0)).not.toHaveData(key, wrongValue)
771
- })
772
-
773
- it("should pass negated if element has no matching key", function () {
774
- expect($('#sandbox')).not.toHaveData(wrongKey, value)
775
- expect($('#sandbox').get(0)).not.toHaveData(wrongKey, value)
776
- })
777
- })
778
-
779
- describe("when the value is a JSON object", function() {
780
- var objectKey = 'object-key'
781
- var objectValue = {'foo': 'bar'}
782
- var objectString = '[object Object]'
783
-
784
- beforeEach(function() {
785
- setFixtures(sandbox().data(objectKey, objectValue))
786
- })
787
-
788
- it("should pass if element has matching key with matching value", function () {
789
- expect($('#sandbox')).toHaveData(objectKey, objectValue)
790
- expect($('#sandbox').get(0)).toHaveData(objectKey, objectValue)
791
- })
792
-
793
- it("should not pass if element has matching key but the value is just a string representation of the value", function () {
794
- expect($('#sandbox')).not.toHaveData(objectKey, objectString)
795
- expect($('#sandbox').get(0)).not.toHaveData(objectKey, objectString)
796
- })
797
-
798
- it("should not pass if element has matching key but the value is just a string representation of the value", function () {
799
- setFixtures('<div id="foo" div data-bar="[object Object]"></div>')
800
- expect($('#foo')).not.toHaveData('bar', { 'answer': 42 })
801
- expect($('#foo').get(0)).not.toHaveData('bar', { 'answer': 42 })
802
- })
803
- })
804
- })
805
-
806
- describe("toBeVisible", function () {
807
- it("should pass on visible element", function () {
808
- setFixtures(sandbox())
809
- expect($('#sandbox')).toBeVisible()
810
- expect($('#sandbox').get(0)).toBeVisible()
811
- })
812
-
813
- it("should pass negated on hidden element", function () {
814
- setFixtures(sandbox().hide())
815
- expect($('#sandbox')).not.toBeVisible()
816
- expect($('#sandbox').get(0)).not.toBeVisible()
817
- })
818
- })
819
-
820
- describe("toBeHidden", function () {
821
- it("should pass on hidden element", function () {
822
- setFixtures(sandbox().hide())
823
- expect($('#sandbox')).toBeHidden()
824
- expect($('#sandbox').get(0)).toBeHidden()
825
- })
826
-
827
- it("should pass negated on visible element", function () {
828
- setFixtures(sandbox())
829
- expect($('#sandbox')).not.toBeHidden()
830
- expect($('#sandbox').get(0)).not.toBeHidden()
831
- })
832
- })
833
-
834
- describe("toBeSelected", function () {
835
- beforeEach(function () {
836
- setFixtures('\
837
- <select>\n\
838
- <option id="not-selected"></option>\n\
839
- <option id="selected" selected="selected"></option>\n\
840
- </select>')
841
- })
842
-
843
- it("should pass on selected element", function () {
844
- expect($('#selected')).toBeSelected()
845
- expect($('#selected').get(0)).toBeSelected()
846
- })
847
-
848
- it("should pass negated on not selected element", function () {
849
- expect($('#not-selected')).not.toBeSelected()
850
- expect($('#not-selected').get(0)).not.toBeSelected()
851
- })
852
- })
853
-
854
- describe("toBeChecked", function () {
855
- beforeEach(function () {
856
- setFixtures('\
857
- <input type="checkbox" id="checked" checked="checked" />\n\
858
- <input type="checkbox" id="not-checked" />\n\
859
- <input type="radio" name="radio-name" id="radio-checked" checked="checked" />')
860
- })
861
-
862
- it("should pass on checked element", function () {
863
- expect($('#checked')).toBeChecked()
864
- expect($('#checked').get(0)).toBeChecked()
865
- })
866
-
867
- it("should pass negated on not checked element", function () {
868
- expect($('#not-checked')).not.toBeChecked()
869
- expect($('#not-checked').get(0)).not.toBeChecked()
870
- })
871
-
872
- it("shoud not change the checked status of a radio button", function () {
873
- expect($('#radio-checked')).toBeChecked()
874
- expect($('#radio-checked')).toBeChecked()
875
- })
876
- })
877
-
878
- describe("toBeEmpty", function () {
879
- it("should pass on empty element", function () {
880
- setFixtures(sandbox())
881
- expect($('#sandbox')).toBeEmpty()
882
- expect($('#sandbox').get(0)).toBeEmpty()
883
- })
884
-
885
- it("should pass negated on element with a tag inside", function () {
886
- setFixtures(sandbox().html($('<span />')))
887
- expect($('#sandbox')).not.toBeEmpty()
888
- expect($('#sandbox').get(0)).not.toBeEmpty()
889
- })
890
-
891
- it("should pass negated on element with text inside", function () {
892
- setFixtures(sandbox().text('some text'))
893
- expect($('#sandbox')).not.toBeEmpty()
894
- expect($('#sandbox').get(0)).not.toBeEmpty()
895
- })
896
- })
897
-
898
- describe("toBeInDOM", function () {
899
- it("should pass on elements in the DOM", function () {
900
- setFixtures(sandbox())
901
- expect($('#sandbox')).toBeInDOM()
902
- })
903
-
904
- it("should pass negated on elements not in the DOM", function () {
905
- expect($('<div>')).not.toBeInDOM()
906
- })
907
- })
908
-
909
- describe("toExist", function () {
910
- it("should pass on visible element", function () {
911
- setFixtures(sandbox())
912
- expect($('#sandbox')).toExist()
913
- expect($('#sandbox').get(0)).toExist()
914
- })
915
-
916
- it("should pass on hidden element", function () {
917
- setFixtures(sandbox().hide())
918
- expect($('#sandbox')).toExist()
919
- expect($('#sandbox').get(0)).toExist()
920
- })
921
-
922
- it("should pass negated if element is not present in DOM", function () {
923
- expect($('#non-existent-element')).not.toExist()
924
- expect($('#non-existent-element').get(0)).not.toExist()
925
- })
926
- })
927
-
928
- describe("toHaveLength", function () {
929
- it("should pass on an object with more than zero items", function () {
930
- var $three = $('<div>').add('<span>').add("<pre>")
931
- expect($three.length).toBe(3)
932
- expect($three).toHaveLength(3)
933
- })
934
-
935
- it("should pass negated on an object with more than zero items", function () {
936
- var $three = $('<div>').add('<span>').add("<pre>")
937
- expect($three.length).toBe(3)
938
- expect($three).not.toHaveLength(2)
939
- })
940
-
941
- it("should pass on an object with zero items", function () {
942
- var $zero = $()
943
- expect($zero.length).toBe(0)
944
- expect($zero).toHaveLength(0)
945
- })
946
-
947
- it("should pass negated on an object with zero items", function () {
948
- var $zero = $()
949
- expect($zero.length).not.toBe(1)
950
- expect($zero).not.toHaveLength(1)
951
- })
952
- })
953
-
954
- describe("toEqual", function () {
955
- beforeEach(function () {
956
- setFixtures(sandbox())
957
- })
958
-
959
- it("should pass if object matches selector", function () {
960
- expect($('#sandbox')).toEqual('#sandbox')
961
- expect($('#sandbox').get(0)).toEqual('#sandbox')
962
- })
963
-
964
- it("should pass negated if object does not match selector", function () {
965
- expect($('#sandbox')).not.toEqual('#wrong-id')
966
- expect($('#sandbox').get(0)).not.toEqual('#wrong-id')
967
- })
968
- })
969
-
970
- describe("toContainElement", function () {
971
- beforeEach(function () {
972
- setFixtures(sandbox().html('<span />'))
973
- })
974
-
975
- it("should pass if object contains selector", function () {
976
- expect($('#sandbox')).toContainElement('span')
977
- expect($('#sandbox').get(0)).toContainElement('span')
978
- })
979
-
980
- it("should pass negated if object does not contain selector", function () {
981
- expect($('#sandbox')).not.toContainElement('div')
982
- expect($('#sandbox').get(0)).not.toContainElement('div')
983
- })
984
- })
985
-
986
- describe("toBeMatchedBy", function () {
987
- beforeEach(function () {
988
- setFixtures(sandbox().html('<span id="js-match"></span>'))
989
- })
990
-
991
- it("should pass if selector contains given selector", function () {
992
- expect($('#sandbox span')).toBeMatchedBy('#js-match')
993
- })
994
-
995
- it("should pass negated if selector does not contain given selector", function () {
996
- expect($('#sandbox span')).not.toBeMatchedBy('#js-match-not')
997
- })
998
- })
999
-
1000
- describe("toBeDisabled", function () {
1001
- beforeEach(function () {
1002
- setFixtures('\
1003
- <input type="text" disabled="disabled" id="disabled"/>\n\
1004
- <input type="text" id="enabled"/>')
1005
- })
1006
-
1007
- it("should pass on disabled element", function () {
1008
- expect($('#disabled')).toBeDisabled()
1009
- expect($('#disabled').get(0)).toBeDisabled()
1010
- })
1011
-
1012
- it("should pass negated on not selected element", function () {
1013
- expect($('#enabled')).not.toBeDisabled()
1014
- expect($('#enabled').get(0)).not.toBeDisabled()
1015
- })
1016
- })
1017
-
1018
- describe("toBeFocused", function () {
1019
- beforeEach(function () {
1020
- setFixtures('<input type="text" id="focused"/>')
1021
- })
1022
-
1023
- it("should pass on focused element", function () {
1024
- var el = $("#focused").focus()
1025
- expect(el).toBeFocused()
1026
- })
1027
-
1028
- it("should pass negated on not focused element", function () {
1029
- var el = $("#focused")
1030
- expect(el).not.toBeFocused()
1031
- })
1032
- })
1033
-
1034
- describe('toHaveBeenTriggeredOn', function () {
1035
- var spyEvents = {}
1036
- beforeEach(function () {
1037
- setFixtures(sandbox().html('<a id="clickme">Click Me</a> <a id="otherlink">Other Link</a>'))
1038
- spyEvents['#clickme'] = spyOnEvent($('#clickme'), 'click')
1039
- spyOnEvent(document, 'click')
1040
- spyOnEvent($('#otherlink'), 'click')
1041
- })
1042
-
1043
- it('should pass if the event was triggered on the object', function () {
1044
- $('#clickme').click()
1045
- expect('click').toHaveBeenTriggeredOn($('#clickme'))
1046
- expect('click').toHaveBeenTriggeredOn('#clickme')
1047
- })
1048
-
1049
- it('should pass if the event was triggered on document', function () {
1050
- $(document).click()
1051
- expect('click').toHaveBeenTriggeredOn($(document))
1052
- expect('click').toHaveBeenTriggeredOn(document)
1053
- })
1054
-
1055
- it('should pass if the event was triggered on a descendant of document', function () {
1056
- $('#clickme').click()
1057
- expect('click').toHaveBeenTriggeredOn($(document))
1058
- expect('click').toHaveBeenTriggeredOn(document)
1059
- })
1060
-
1061
- it('should pass negated if the event was never triggered', function () {
1062
- expect('click').not.toHaveBeenTriggeredOn($('#clickme'))
1063
- expect('click').not.toHaveBeenTriggeredOn('#clickme')
1064
- })
1065
-
1066
- it('should pass negated if the event was triggered on another non-descendant object', function () {
1067
- $('#otherlink').click()
1068
- expect('click').not.toHaveBeenTriggeredOn($('#clickme'))
1069
- expect('click').not.toHaveBeenTriggeredOn('#clickme')
1070
- })
1071
-
1072
- it('should pass if the event call count is incremented', function () {
1073
- expect(spyEvents['#clickme'].calls.any()).toEqual(false);
1074
- expect(spyEvents['#clickme'].calls.count()).toEqual(0);
1075
- $('#clickme').click()
1076
- expect('click').toHaveBeenTriggeredOn($('#clickme'))
1077
- expect('click').toHaveBeenTriggeredOn('#clickme')
1078
- expect(spyEvents['#clickme'].calls.count()).toEqual(1);
1079
- expect(spyEvents['#clickme'].calls.any()).toEqual(true);
1080
- $('#clickme').click()
1081
- $('#clickme').click()
1082
- expect(spyEvents['#clickme'].calls.count()).toEqual(3);
1083
- expect(spyEvents['#clickme'].calls.any()).toEqual(true);
1084
- })
1085
- })
1086
-
1087
- describe('toHaveBeenTriggeredOnAndWith', function () {
1088
- beforeEach(function () {
1089
- spyOnEvent(document, 'event')
1090
- })
1091
-
1092
- describe("when extra parameter is an object", function () {
1093
- it('should pass if the event was triggered on the object with expected arguments', function () {
1094
- $(document).trigger('event', { key1: "value1", key2: "value2" })
1095
- expect('event').toHaveBeenTriggeredOnAndWith(document, { key1: "value1", key2: "value2" })
1096
- })
1097
-
1098
- it('should pass negated if the event was never triggered', function () {
1099
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, { key1: "value1", key2: "value2" })
1100
- })
1101
-
1102
- it('should pass negated if the event was triggered on another non-descendant object', function () {
1103
- $(window).trigger('event', { key1: "value1", key2: "value2" })
1104
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, { key1: "value1", key2: "value2" })
1105
- })
1106
-
1107
- it('should pass negated if the event was triggered but the arguments do not match with the expected arguments', function () {
1108
- $(document).trigger('event', { key1: "value1" })
1109
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, { key1: "value1", key2: "value2" })
1110
- $(document).trigger('event', { key1: "value1", key2: "value2" })
1111
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, { key1: "value1" })
1112
- $(document).trigger('event', { key1: "different value" })
1113
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, { key1: "value1" })
1114
- $(document).trigger('event', { different_key: "value1" })
1115
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, { key1: "value1" })
1116
- })
1117
-
1118
- it('should pass if the arguments match using jasmine.objectContaining', function () {
1119
- $(document).trigger('event', { key1: "value1", key2: "value2" })
1120
- expect('event').toHaveBeenTriggeredOnAndWith(document, jasmine.objectContaining({ key1: "value1" }))
1121
- })
1122
- })
1123
-
1124
- describe("when extra parameter is an array", function () {
1125
- it('should pass if the event was triggered on the object with expected arguments', function () {
1126
- $(document).trigger('event', [1, 2])
1127
- expect('event').toHaveBeenTriggeredOnAndWith(document, [1, 2])
1128
- })
1129
-
1130
- it('should pass negated if the event was never triggered', function () {
1131
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, [1, 2])
1132
- })
1133
-
1134
- it('should pass negated if the event was triggered on another non-descendant object', function () {
1135
- $(window).trigger('event', [1, 2])
1136
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, [1, 2])
1137
- })
1138
-
1139
- it('should pass negated if the event was triggered but the arguments do not match with the expected arguments', function () {
1140
- $(document).trigger('event', [1])
1141
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, [1, 2])
1142
- $(document).trigger('event', [1, 2])
1143
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, [1])
1144
- $(document).trigger('event', [1, 3])
1145
- expect('event').not.toHaveBeenTriggeredOnAndWith(document, [1, 2])
1146
- })
1147
- })
1148
- })
1149
-
1150
- describe('toHaveBeenTriggered', function () {
1151
- var spyEvents = {}
1152
- beforeEach(function () {
1153
- setFixtures(sandbox().html('<a id="clickme">Click Me</a> <a id="otherlink">Other Link</a>'))
1154
- spyEvents['#clickme'] = spyOnEvent($('#clickme'), 'click')
1155
- spyEvents['#otherlink'] = spyOnEvent($('#otherlink'), 'click')
1156
- })
1157
-
1158
- it('should pass if the event was triggered on the object', function () {
1159
- $('#clickme').click()
1160
- expect(spyEvents['#clickme']).toHaveBeenTriggered()
1161
- })
1162
-
1163
- it('should pass negated if the event was never triggered', function () {
1164
- expect(spyEvents['#clickme']).not.toHaveBeenTriggered()
1165
- })
1166
-
1167
- it('should pass negated if the event was triggered on another non-descendant object', function () {
1168
- $('#otherlink').click()
1169
- expect(spyEvents['#clickme']).not.toHaveBeenTriggered()
1170
- })
1171
-
1172
- it('should pass negated if the spy event was reset', function (){
1173
- $('#clickme').click()
1174
- expect('click').toHaveBeenTriggeredOn($('#clickme'))
1175
- expect('click').toHaveBeenTriggeredOn('#clickme')
1176
- expect(spyEvents['#clickme']).toHaveBeenTriggered()
1177
- spyEvents['#clickme'].reset()
1178
- expect('click').not.toHaveBeenTriggeredOn($('#clickme'))
1179
- expect('click').not.toHaveBeenTriggeredOn('#clickme')
1180
- expect(spyEvents['#clickme']).not.toHaveBeenTriggered()
1181
- })
1182
-
1183
- it('should pass if the event call count is incremented', function () {
1184
- expect(spyEvents['#clickme'].calls.any()).toEqual(false);
1185
- expect(spyEvents['#clickme'].calls.count()).toEqual(0);
1186
- $('#clickme').click()
1187
- expect(spyEvents['#clickme']).toHaveBeenTriggered()
1188
- expect(spyEvents['#clickme'].calls.count()).toEqual(1);
1189
- expect(spyEvents['#clickme'].calls.any()).toEqual(true);
1190
- $('#clickme').click()
1191
- $('#clickme').click()
1192
- expect(spyEvents['#clickme'].calls.count()).toEqual(3);
1193
- expect(spyEvents['#clickme'].calls.any()).toEqual(true);
1194
- })
1195
- })
1196
-
1197
- describe('toHaveBeenPreventedOn', function () {
1198
- beforeEach(function () {
1199
- setFixtures(sandbox().html('<a id="clickme">Click Me</a> <a id="otherlink">Other Link</a>'))
1200
- spyOnEvent($('#clickme'), 'click')
1201
- spyOnEvent($('#otherlink'), 'click')
1202
- })
1203
-
1204
- it('should pass if the event was prevented on the object', function () {
1205
- $('#clickme').bind('click', function (event) {
1206
- event.preventDefault()
1207
- })
1208
- $('#clickme').click()
1209
- expect('click').toHaveBeenPreventedOn($('#clickme'))
1210
- expect('click').toHaveBeenPreventedOn('#clickme')
1211
- })
1212
-
1213
- it('should pass negated if the event was never prevented', function () {
1214
- $('#clickme').click()
1215
- expect('click').not.toHaveBeenPreventedOn($('#clickme'))
1216
- expect('click').not.toHaveBeenPreventedOn('#clickme')
1217
- })
1218
-
1219
- it('should pass negated if the event was prevented on another non-descendant object', function () {
1220
- $('#otherlink').bind('click', function (event) {
1221
- event.preventDefault()
1222
- })
1223
- $('#clickme').click()
1224
- expect('click').not.toHaveBeenPreventedOn($('#clickme'))
1225
- })
1226
- })
1227
-
1228
- describe('toHaveBeenPrevented', function () {
1229
- var spyEvents = {}
1230
- beforeEach(function () {
1231
- setFixtures(sandbox().html('<a id="clickme">Click Me</a> <a id="otherlink">Other Link</a>'))
1232
- spyEvents['#clickme'] = spyOnEvent($('#clickme'), 'click')
1233
- spyEvents['#otherlink'] = spyOnEvent($('#otherlink'), 'click')
1234
- })
1235
-
1236
- it('should pass if the event was prevented on the object', function () {
1237
- $('#clickme').bind('click', function (event) {
1238
- event.preventDefault()
1239
- })
1240
- $('#clickme').click()
1241
- expect(spyEvents['#clickme']).toHaveBeenPrevented()
1242
- })
1243
-
1244
- it('should pass negated if the event was never prevented', function () {
1245
- $('#clickme').click()
1246
- expect(spyEvents['#clickme']).not.toHaveBeenPrevented()
1247
- })
1248
-
1249
- it('should pass negated if the event was prevented on another non-descendant object', function () {
1250
- $('#otherlink').bind('click', function (event) {
1251
- event.preventDefault()
1252
- })
1253
- $('#clickme').click()
1254
- expect(spyEvents['#clickme']).not.toHaveBeenPrevented()
1255
- })
1256
-
1257
- it('should pass negated if nothing was triggered', function () {
1258
- expect(spyEvents['#clickme']).not.toHaveBeenPrevented()
1259
- })
1260
-
1261
- })
1262
-
1263
- describe('toHaveBeenStoppedOn', function () {
1264
- beforeEach(function () {
1265
- setFixtures(sandbox().html('<a id="clickme">Click Me</a> <a id="otherlink">Other Link</a>'))
1266
- spyOnEvent($('#clickme'), 'click')
1267
- spyOnEvent($('#otherlink'), 'click')
1268
- })
1269
-
1270
- it('should pass if the event was stopped on the object', function () {
1271
- $('#clickme').bind('click', function (event) {
1272
- event.stopPropagation()
1273
- })
1274
- $('#clickme').click()
1275
- expect('click').toHaveBeenStoppedOn($('#clickme'))
1276
- expect('click').toHaveBeenStoppedOn('#clickme')
1277
- })
1278
-
1279
- it('should pass negated if the event was never stopped', function () {
1280
- $('#clickme').click()
1281
- expect('click').not.toHaveBeenStoppedOn($('#clickme'))
1282
- expect('click').not.toHaveBeenStoppedOn('#clickme')
1283
- })
1284
-
1285
- it('should pass negated if the event was stopped on another non-descendant object', function () {
1286
- $('#otherlink').bind('click', function (event) {
1287
- event.stopPropagation()
1288
- })
1289
- $('#clickme').click()
1290
- expect('click').not.toHaveBeenStoppedOn($('#clickme'))
1291
- })
1292
- })
1293
-
1294
- describe('toHaveBeenStopped', function () {
1295
- var spyEvents = {}
1296
- beforeEach(function () {
1297
- setFixtures(sandbox().html('<a id="clickme">Click Me</a> <a id="otherlink">Other Link</a>'))
1298
- spyEvents['#clickme'] = spyOnEvent($('#clickme'), 'click')
1299
- spyEvents['#otherlink'] = spyOnEvent($('#otherlink'), 'click')
1300
- })
1301
-
1302
- it('should pass if the event was stopped on the object', function () {
1303
- $('#clickme').bind('click', function (event) {
1304
- event.stopPropagation()
1305
- })
1306
- $('#clickme').click()
1307
- expect(spyEvents['#clickme']).toHaveBeenStopped()
1308
- })
1309
-
1310
- it('should pass negated if the event was never stopped', function () {
1311
- $('#clickme').click()
1312
- expect(spyEvents['#clickme']).not.toHaveBeenStopped()
1313
- })
1314
-
1315
- it('should pass negated if the event was stopped on another non-descendant object', function () {
1316
- $('#otherlink').bind('click', function (event) {
1317
- event.stopPropagation()
1318
- })
1319
- $('#clickme').click()
1320
- expect(spyEvents['#clickme']).not.toHaveBeenStopped()
1321
- })
1322
-
1323
- it('should pass negated if nothing was triggered', function () {
1324
- expect(spyEvents['#clickme']).not.toHaveBeenStopped()
1325
- })
1326
- })
1327
-
1328
- describe('toHandle', function () {
1329
- var handler
1330
- beforeEach(function () {
1331
- setFixtures(sandbox().html('<a id="clickme">Click Me</a> <a id="otherlink">Other Link</a>'))
1332
- handler = function (){}
1333
- })
1334
-
1335
- it("should handle events on the window object", function (){
1336
- $(window).bind("resize", handler)
1337
- expect($(window)).toHandle("resize")
1338
- })
1339
-
1340
- it('should pass if the event is bound', function () {
1341
- $('#clickme').bind("click", handler)
1342
- expect($('#clickme')).toHandle("click")
1343
- expect($('#clickme').get(0)).toHandle("click")
1344
- })
1345
-
1346
- it('should pass if the event is not bound', function () {
1347
- expect($('#clickme')).not.toHandle("click")
1348
- expect($('#clickme').get(0)).not.toHandle("click")
1349
- })
1350
-
1351
- it('should pass if the namespaced event is bound', function (){
1352
- $('#clickme').bind("click", handler); //another event for the click array
1353
- $('#clickme').bind("click.NameSpace", handler)
1354
- expect($('#clickme')).toHandle("click.NameSpace")
1355
- })
1356
-
1357
- it('should not fail when events is empty', function () {
1358
- $('#clickme').change(function () { })
1359
- expect($('#clickme')).not.toHandle('click')
1360
- })
1361
-
1362
- it('should recognize an event with multiple namespaces', function (){
1363
- $('#clickme').bind("click.NSone.NStwo.NSthree", handler)
1364
- expect($('#clickme')).toHandle("click.NSone")
1365
- expect($('#clickme')).toHandle("click.NStwo")
1366
- expect($('#clickme')).toHandle("click.NSthree")
1367
- expect($('#clickme')).toHandle("click.NSthree.NStwo")
1368
- expect($('#clickme')).toHandle("click.NStwo.NSone")
1369
- expect($('#clickme')).toHandle("click")
1370
- })
1371
-
1372
- it('should pass if a namespaced event is not bound', function () {
1373
- $('#clickme').bind("click", handler); //non namespaced event
1374
- $('#clickme').bind("click.OtherNameSpace", handler); //different namespaced event
1375
- expect($('#clickme')).not.toHandle("click.NameSpace")
1376
- })
1377
-
1378
- it('should handle event on any object', function (){
1379
- var object = new function (){}
1380
- $(object).bind('click', function (){})
1381
- expect($(object)).toHandle('click')
1382
- })
1383
-
1384
- it('should not fail when actual has no matches', function (){
1385
- expect($('#notreal')).not.toHandle('click')
1386
- })
1387
-
1388
- it('should not fail when actual is null', function (){
1389
- expect(null).not.toHandle('click')
1390
- })
1391
-
1392
- })
1393
-
1394
- describe('toHandleWith', function () {
1395
- beforeEach(function () {
1396
- setFixtures(sandbox().html('<a id="clickme">Click Me</a> <a id="otherlink">Other Link</a>'))
1397
- })
1398
-
1399
- it('should pass if the event is bound with the given handler', function () {
1400
- var handler = function (){}
1401
- $('#clickme').bind("click", handler)
1402
- expect($('#clickme')).toHandleWith("click", handler)
1403
- expect($('#clickme').get(0)).toHandleWith("click", handler)
1404
- })
1405
-
1406
- it('should pass if the event is not bound with the given handler', function () {
1407
- var handler = function (){}
1408
- $('#clickme').bind("click", handler)
1409
-
1410
- var aDifferentHandler = function (){}
1411
- expect($('#clickme')).not.toHandleWith("click", aDifferentHandler)
1412
- expect($('#clickme').get(0)).not.toHandleWith("click", aDifferentHandler)
1413
- })
1414
-
1415
- it('should pass if the event is not bound at all', function () {
1416
- expect($('#clickme')).not.toHandle("click")
1417
- expect($('#clickme').get(0)).not.toHandle("click")
1418
- })
1419
-
1420
- it("should pass if the event on window is bound with the given handler", function (){
1421
- var handler = function (){}
1422
- $(window).bind("resize", handler)
1423
- expect($(window)).toHandleWith("resize", handler)
1424
- })
1425
-
1426
- it("should pass if the event on any object is bound with the given handler", function (){
1427
- var object = new function (){}
1428
- var handler = function (){}
1429
- $(object).bind('click', handler)
1430
- expect($(object)).toHandleWith('click', handler)
1431
- })
1432
-
1433
- it("should pass if the namespaced event is bound with the given handler", function () {
1434
- var handler = function (){}
1435
- $('#clickme').bind("click.namespaced", handler)
1436
- expect($('#clickme')).toHandleWith("click.namespaced", handler)
1437
- expect($('#clickme').get(0)).toHandleWith("click.namespaced", handler)
1438
- })
1439
-
1440
- it('should pass if the namespaced event is not bound with the given handler', function () {
1441
- var handler = function (){}
1442
- $('#clickme').bind("click", handler)
1443
-
1444
- var aDifferentHandler = function (){}
1445
- expect($('#clickme')).not.toHandleWith("click.namespaced", aDifferentHandler)
1446
- expect($('#clickme').get(0)).not.toHandleWith("click.namespaced", aDifferentHandler)
1447
- })
1448
-
1449
- it('should pass if the namespaced event is not bound at all', function () {
1450
- expect($('#clickme')).not.toHandle("click.namespaced")
1451
- expect($('#clickme').get(0)).not.toHandle("click.namespaced")
1452
- })
1453
-
1454
- it("should pass if the namespaced event on window is bound with the given handler", function (){
1455
- var handler = function (){}
1456
- $(window).bind("resize.namespaced", handler)
1457
- expect($(window)).toHandleWith("resize.namespaced", handler)
1458
- })
1459
-
1460
- it("should pass if the namespaced event on any object is bound with the given handler", function (){
1461
- var object = new function (){}
1462
- var handler = function (){}
1463
- $(object).bind('click.namespaced', handler)
1464
- expect($(object)).toHandleWith('click.namespaced', handler)
1465
- })
1466
-
1467
- it('should not fail when actual has no matches', function (){
1468
- expect($('#notreal')).not.toHandleWith('click')
1469
- })
1470
-
1471
- it('should not fail when actual is null', function (){
1472
- expect(null).not.toHandleWith('click')
1473
- })
1474
-
1475
- })
1476
- })
1477
-
1478
- describe("jasmine.StyleFixtures", function () {
1479
- var ajaxData = 'some ajax data'
1480
- var fixtureUrl = 'some_url'
1481
- var anotherFixtureUrl = 'another_url'
1482
- var fixturesContainer = function () {
1483
- return $('head style').last()
1484
- }
1485
-
1486
- beforeEach(function () {
1487
- jasmine.getStyleFixtures().clearCache()
1488
- spyOn(jasmine.StyleFixtures.prototype, 'loadFixtureIntoCache_').and.callFake(function (relativeUrl){
1489
- this.fixturesCache_[relativeUrl] = ajaxData
1490
- })
1491
- })
1492
-
1493
- describe("default initial config values", function () {
1494
- it("should set 'spec/javascripts/fixtures' as the default style fixtures path", function () {
1495
- expect(jasmine.getStyleFixtures().fixturesPath).toEqual('spec/javascripts/fixtures')
1496
- })
1497
- })
1498
-
1499
- describe("load", function () {
1500
- it("should insert CSS fixture within style tag into HEAD", function () {
1501
- var stylesNumOld = $('head style').length
1502
-
1503
- jasmine.getStyleFixtures().load(fixtureUrl)
1504
- expect($('head style').length - stylesNumOld).toEqual(1)
1505
- expect(fixturesContainer().html()).toEqual(ajaxData)
1506
- })
1507
-
1508
- it("should insert duplicated CSS fixture into one style tag when the same url is provided twice in a single call", function () {
1509
- jasmine.getStyleFixtures().load(fixtureUrl, fixtureUrl)
1510
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
1511
- })
1512
-
1513
- it("should insert merged CSS of two fixtures into one style tag when two different urls are provided in a single call", function () {
1514
- jasmine.getStyleFixtures().load(fixtureUrl, anotherFixtureUrl)
1515
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
1516
- })
1517
-
1518
- it("should have shortcut global method loadStyleFixtures", function () {
1519
- loadStyleFixtures(fixtureUrl, anotherFixtureUrl)
1520
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
1521
- })
1522
- })
1523
-
1524
- describe("appendLoad", function () {
1525
- beforeEach(function (){
1526
- ajaxData = 'some ajax data'
1527
- })
1528
-
1529
- it("should insert CSS fixture within style tag into HEAD", function () {
1530
- var stylesNumOld = $('head style').length
1531
-
1532
- jasmine.getStyleFixtures().appendLoad(fixtureUrl)
1533
- expect($('head style').length - stylesNumOld).toEqual(1)
1534
- expect(fixturesContainer().html()).toEqual(ajaxData)
1535
- })
1536
-
1537
- it("should insert duplicated CSS fixture into one style tag when the same url is provided twice in a single call", function () {
1538
- jasmine.getStyleFixtures().appendLoad(fixtureUrl, fixtureUrl)
1539
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
1540
- })
1541
-
1542
- it("should insert merged CSS of two fixtures into one style tag when two different urls are provided in a single call", function () {
1543
- jasmine.getStyleFixtures().appendLoad(fixtureUrl, anotherFixtureUrl)
1544
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
1545
- })
1546
-
1547
- it("should have shortcut global method appendLoadStyleFixtures", function () {
1548
- appendLoadStyleFixtures(fixtureUrl, anotherFixtureUrl)
1549
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
1550
- })
1551
-
1552
- describe("with a prexisting fixture",function (){
1553
- beforeEach(function () {
1554
- jasmine.getStyleFixtures().appendLoad(fixtureUrl)
1555
- })
1556
-
1557
- it("should add new content within new style tag in HEAD", function () {
1558
- jasmine.getStyleFixtures().appendLoad(anotherFixtureUrl)
1559
- expect(fixturesContainer().html()).toEqual(ajaxData)
1560
- })
1561
-
1562
- it("should not delete prexisting fixtures", function () {
1563
- jasmine.getStyleFixtures().appendLoad(anotherFixtureUrl)
1564
- expect(fixturesContainer().prev().html()).toEqual(ajaxData)
1565
- })
1566
- })
1567
- })
1568
-
1569
- describe("preload", function () {
1570
- describe("load after preload", function () {
1571
- it("should go from cache", function () {
1572
- jasmine.getStyleFixtures().preload(fixtureUrl, anotherFixtureUrl)
1573
- jasmine.getStyleFixtures().load(fixtureUrl, anotherFixtureUrl)
1574
- expect(jasmine.StyleFixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(2)
1575
- })
1576
-
1577
- it("should return correct CSSs", function () {
1578
- jasmine.getStyleFixtures().preload(fixtureUrl, anotherFixtureUrl)
1579
- jasmine.getStyleFixtures().load(fixtureUrl, anotherFixtureUrl)
1580
- expect(fixturesContainer().html()).toEqual(ajaxData + ajaxData)
1581
- })
1582
- })
1583
-
1584
- it("should not preload the same fixture twice", function () {
1585
- jasmine.getStyleFixtures().preload(fixtureUrl, fixtureUrl)
1586
- expect(jasmine.StyleFixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(1)
1587
- })
1588
-
1589
- it("should have shortcut global method preloadStyleFixtures", function () {
1590
- preloadStyleFixtures(fixtureUrl, anotherFixtureUrl)
1591
- expect(jasmine.StyleFixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(2)
1592
- })
1593
- })
1594
-
1595
- describe("set", function () {
1596
- var css = 'body { color: red }'
1597
-
1598
- it("should insert CSS within style tag into HEAD", function () {
1599
- var stylesNumOld = $('head style').length
1600
-
1601
- jasmine.getStyleFixtures().set(css)
1602
- expect($('head style').length - stylesNumOld).toEqual(1)
1603
- expect(fixturesContainer().html()).toEqual(css)
1604
- })
1605
-
1606
- it("should have shortcut global method setStyleFixtures", function () {
1607
- setStyleFixtures(css)
1608
- expect(fixturesContainer().html()).toEqual(css)
1609
- })
1610
- })
1611
-
1612
- describe("appendSet",function (){
1613
- var css = 'body { color: red }'
1614
-
1615
- it("should insert CSS within style tag into HEAD", function () {
1616
- var stylesNumOld = $('head style').length
1617
-
1618
- jasmine.getStyleFixtures().appendSet(css)
1619
- expect($('head style').length - stylesNumOld).toEqual(1)
1620
- expect(fixturesContainer().html()).toEqual(css)
1621
- })
1622
-
1623
- it("should have shortcut global method appendSetStyleFixtures", function () {
1624
- appendSetStyleFixtures(css)
1625
- expect(fixturesContainer().html()).toEqual(css)
1626
- })
1627
-
1628
- describe("when fixture container exists", function () {
1629
- beforeEach(function () {
1630
- jasmine.getStyleFixtures().appendSet(css)
1631
- })
1632
-
1633
- it("should add new content within new style tag in HEAD", function () {
1634
- jasmine.getStyleFixtures().appendSet(css)
1635
- expect(fixturesContainer().html()).toEqual(css)
1636
- })
1637
-
1638
- it("should not delete prexisting fixtures", function () {
1639
- jasmine.getStyleFixtures().appendSet(css)
1640
- expect(fixturesContainer().prev().html()).toEqual(css)
1641
- })
1642
- })
1643
- })
1644
-
1645
- describe("cleanUp", function () {
1646
- it("should remove CSS fixtures from DOM", function () {
1647
- var stylesNumOld = $('head style').length
1648
-
1649
- jasmine.getStyleFixtures().load(fixtureUrl, anotherFixtureUrl)
1650
- jasmine.getStyleFixtures().cleanUp()
1651
-
1652
- expect($('head style').length).toEqual(stylesNumOld)
1653
- })
1654
- })
1655
-
1656
- describe("automatic DOM clean-up between tests", function () {
1657
- var stylesNumOld = $('head style').length
1658
-
1659
- // WARNING: this test must be invoked first (before 'SECOND TEST')!
1660
- it("FIRST TEST: should pollute the DOM", function () {
1661
- jasmine.getStyleFixtures().load(fixtureUrl)
1662
- expect($('head style').length).toEqual(stylesNumOld + 1)
1663
- })
1664
-
1665
- // WARNING: this test must be invoked second (after 'FIRST TEST')!
1666
- it("SECOND TEST: should see the DOM in a blank state", function () {
1667
- expect($('head style').length).toEqual(stylesNumOld)
1668
- })
1669
- })
1670
- })
1671
-
1672
- describe("jasmine.StyleFixtures using real AJAX call", function () {
1673
- var defaultFixturesPath
1674
-
1675
- beforeEach(function () {
1676
- defaultFixturesPath = jasmine.getStyleFixtures().fixturesPath
1677
- jasmine.getStyleFixtures().fixturesPath = 'spec/fixtures'
1678
- })
1679
-
1680
- afterEach(function () {
1681
- jasmine.getStyleFixtures().fixturesPath = defaultFixturesPath
1682
- })
1683
-
1684
- describe("when fixture file exists", function () {
1685
- var fixtureUrl = "real_non_mocked_fixture_style.css"
1686
-
1687
- it("should load content of fixture file", function () {
1688
- jasmine.getStyleFixtures().load(fixtureUrl)
1689
- expect($('head style').last().html()).toEqual('body { background: red; }')
1690
- })
1691
- })
1692
- })
1693
-
1694
- describe("jasmine.JSONFixtures", function () {
1695
- var ajaxData = {a:1, b:2, arr: [1,2,'stuff'], hsh: { blurp: 8, blop: 'blip' }}
1696
- var moreAjaxData = [1,2,'stuff']
1697
- var fixtureUrl = 'some_json'
1698
- var anotherFixtureUrl = 'another_json'
1699
- var _sortedKeys = function (obj) {
1700
- var arr = []
1701
- for(var k in obj) arr.push(k)
1702
- return arr.sort()
1703
- }
1704
-
1705
- beforeEach(function () {
1706
- jasmine.getJSONFixtures().clearCache()
1707
- spyOn(jasmine.JSONFixtures.prototype, 'loadFixtureIntoCache_').and.callFake(function (relativeUrl){
1708
- fakeData = {}
1709
- // we put the data directly here, instead of using the variables to simulate rereading the file
1710
- fakeData[fixtureUrl] = {a:1, b:2, arr: [1,2,'stuff'], hsh: { blurp: 8, blop: 'blip' }}
1711
- fakeData[anotherFixtureUrl] = [1,2,'stuff']
1712
- this.fixturesCache_[relativeUrl] = fakeData[relativeUrl]
1713
- })
1714
- })
1715
-
1716
- describe("default initial config values", function () {
1717
- it("should set 'spec/javascripts/fixtures/json' as the default style fixtures path", function () {
1718
- expect(jasmine.getJSONFixtures().fixturesPath).toEqual('spec/javascripts/fixtures/json')
1719
- })
1720
- })
1721
-
1722
- describe("load", function () {
1723
- it("should load the JSON data under the key 'fixture_url'", function () {
1724
- data = jasmine.getJSONFixtures().load(fixtureUrl)
1725
- expect(_sortedKeys(data)).toEqual([fixtureUrl])
1726
- expect(data[fixtureUrl]).toEqual(ajaxData)
1727
- })
1728
-
1729
- it("should load the JSON data under the key 'fixture_url', even if it's loaded twice in one call", function () {
1730
- data = jasmine.getJSONFixtures().load(fixtureUrl, fixtureUrl)
1731
- expect(_sortedKeys(data)).toEqual([fixtureUrl])
1732
- })
1733
-
1734
- it("should load the JSON data under 2 keys given two files in a single call", function () {
1735
- data = jasmine.getJSONFixtures().load(anotherFixtureUrl, fixtureUrl)
1736
- expect(_sortedKeys(data)).toEqual([anotherFixtureUrl, fixtureUrl])
1737
- expect(data[anotherFixtureUrl]).toEqual(moreAjaxData)
1738
- expect(data[fixtureUrl]).toEqual(ajaxData)
1739
- })
1740
-
1741
- it("should have shortcut global method loadJSONFixtures", function () {
1742
- data = loadJSONFixtures(fixtureUrl, anotherFixtureUrl)
1743
- expect(_sortedKeys(data)).toEqual([anotherFixtureUrl, fixtureUrl])
1744
- expect(data[anotherFixtureUrl]).toEqual(moreAjaxData)
1745
- expect(data[fixtureUrl]).toEqual(ajaxData)
1746
- })
1747
- })
1748
-
1749
- describe('getJSONFixture', function () {
1750
- it("fetches the fixture you ask for", function () {
1751
- expect(getJSONFixture(fixtureUrl)).toEqual(ajaxData)
1752
- expect(jasmine.JSONFixtures.prototype.loadFixtureIntoCache_).toHaveBeenCalled()
1753
- expect(getJSONFixture(anotherFixtureUrl)).toEqual(moreAjaxData)
1754
- expect(jasmine.JSONFixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(2)
1755
- })
1756
-
1757
- it("retrieves from cache on subsequent requests for the same fixture", function () {
1758
- expect(getJSONFixture(fixtureUrl)).toEqual(ajaxData)
1759
- expect(jasmine.JSONFixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(1)
1760
- expect(getJSONFixture(fixtureUrl)).toEqual(ajaxData)
1761
- expect(jasmine.JSONFixtures.prototype.loadFixtureIntoCache_.calls.count()).toEqual(1)
1762
- })
1763
- })
1764
-
1765
- describe("reloading data will restore the fixture data", function () {
1766
- var data
1767
- beforeEach(function () {
1768
- data = jasmine.getJSONFixtures().load(anotherFixtureUrl)[anotherFixtureUrl]
1769
- })
1770
- // WARNING: this test must be invoked first (before 'SECOND TEST')!
1771
- it("FIRST TEST: should pollute the fixture data", function () {
1772
- data.push('moredata')
1773
- expect(data.length).toEqual(4)
1774
- })
1775
-
1776
- // WARNING: this test must be invoked second (after 'FIRST TEST')!
1777
- it("SECOND TEST: should see cleansed JSON fixture data", function () {
1778
- expect(data.length).toEqual(3)
1779
- })
1780
- })
1781
- })
1782
-
1783
- describe("jasmine.JSONFixtures using real AJAX call", function () {
1784
- var defaultFixturesPath
1785
-
1786
- beforeEach(function () {
1787
- defaultFixturesPath = jasmine.getJSONFixtures().fixturesPath
1788
- jasmine.getJSONFixtures().fixturesPath = 'spec/fixtures/json'
1789
- })
1790
-
1791
- afterEach(function () {
1792
- jasmine.getJSONFixtures().fixturesPath = defaultFixturesPath
1793
- })
1794
-
1795
- describe("when fixture file exists", function () {
1796
- var fixtureUrl = "jasmine_json_test.json"
1797
-
1798
- it("should load content of fixture file", function () {
1799
- data = jasmine.getJSONFixtures().load(fixtureUrl)
1800
- expect(data[fixtureUrl]).toEqual([1,2,3])
1801
- })
1802
- })
1803
- })
1804
-
1805
- describe("jasmine.Env.equalityTesters_", function () {
1806
- describe("jQuery object tester", function () {
1807
- beforeEach(function () {
1808
- setFixtures(sandbox())
1809
- })
1810
-
1811
- it("should equate the same element with different selectors", function () {
1812
- expect($('#sandbox')).toEqual($('div#sandbox'))
1813
- })
1814
-
1815
- it("should equate jquery objects that match a set of elements", function () {
1816
- $('#sandbox').append($('<div></div>'))
1817
- $('#sandbox').append($('<div></div>'))
1818
- expect($('#sandbox div')).toEqual($('div#sandbox div'))
1819
- })
1820
-
1821
- it("should not equate jquery objects that match a set of elements where one has an extra", function () {
1822
- $('#sandbox').append($('<div></div>'))
1823
- $('#sandbox').append($('<div></div>'))
1824
- $('#sandbox').append($('<span></span>'))
1825
- expect($('#sandbox div')).not.toEqual($('div#sandbox div, div#sandbox span'))
1826
- })
1827
-
1828
- it("should not equate jquery objects that match a set of elements of the same type where the tag types are the same, but they are not the same DOM elements", function () {
1829
- $('#sandbox').append($('<div class="one"></div>'))
1830
- $('#sandbox').append($('<span class="one"></span>'))
1831
- $('#sandbox').append($('<div class="two"></div>'))
1832
- $('#sandbox').append($('<span class="two"></span>'))
1833
- expect($('.one')).not.toEqual($('.two').first())
1834
- })
1835
-
1836
- it("should not equate jquery objects that match a set of elements of the same type where one is missing a single element", function () {
1837
- $('#sandbox').append($('<div></div>'))
1838
- $('#sandbox').append($('<div></div>'))
1839
- expect($('#sandbox div')).not.toEqual($('div#sandbox div').first())
1840
- })
1841
- })
1842
- });