[0] | 1 | var readFixtures = function() {
|
---|
[19] | 2 | return jasmine.getFixtures().proxyCallTo_('read', arguments)
|
---|
| 3 | }
|
---|
[0] | 4 |
|
---|
| 5 | var preloadFixtures = function() {
|
---|
[19] | 6 | jasmine.getFixtures().proxyCallTo_('preload', arguments)
|
---|
| 7 | }
|
---|
[0] | 8 |
|
---|
| 9 | var loadFixtures = function() {
|
---|
[19] | 10 | jasmine.getFixtures().proxyCallTo_('load', arguments)
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | var appendLoadFixtures = function() {
|
---|
| 14 | jasmine.getFixtures().proxyCallTo_('appendLoad', arguments)
|
---|
| 15 | }
|
---|
[0] | 16 |
|
---|
| 17 | var setFixtures = function(html) {
|
---|
[19] | 18 | jasmine.getFixtures().proxyCallTo_('set', arguments)
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | var appendSetFixtures = function() {
|
---|
| 22 | jasmine.getFixtures().proxyCallTo_('appendSet', arguments)
|
---|
| 23 | }
|
---|
[0] | 24 |
|
---|
| 25 | var sandbox = function(attributes) {
|
---|
[19] | 26 | return jasmine.getFixtures().sandbox(attributes)
|
---|
| 27 | }
|
---|
[0] | 28 |
|
---|
| 29 | var spyOnEvent = function(selector, eventName) {
|
---|
[19] | 30 | return jasmine.JQuery.events.spyOn(selector, eventName)
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | var preloadStyleFixtures = function() {
|
---|
| 34 | jasmine.getStyleFixtures().proxyCallTo_('preload', arguments)
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | var loadStyleFixtures = function() {
|
---|
| 38 | jasmine.getStyleFixtures().proxyCallTo_('load', arguments)
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | var appendLoadStyleFixtures = function() {
|
---|
| 42 | jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments)
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | var setStyleFixtures = function(html) {
|
---|
| 46 | jasmine.getStyleFixtures().proxyCallTo_('set', arguments)
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | var appendSetStyleFixtures = function(html) {
|
---|
| 50 | jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments)
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | var loadJSONFixtures = function() {
|
---|
| 54 | return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | var getJSONFixture = function(url) {
|
---|
| 58 | return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | jasmine.spiedEventsKey = function (selector, eventName) {
|
---|
| 62 | return [$(selector).selector, eventName].toString()
|
---|
[0] | 63 | }
|
---|
| 64 |
|
---|
| 65 | jasmine.getFixtures = function() {
|
---|
[19] | 66 | return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures()
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | jasmine.getStyleFixtures = function() {
|
---|
| 70 | return jasmine.currentStyleFixtures_ = jasmine.currentStyleFixtures_ || new jasmine.StyleFixtures()
|
---|
| 71 | }
|
---|
[0] | 72 |
|
---|
| 73 | jasmine.Fixtures = function() {
|
---|
[19] | 74 | this.containerId = 'jasmine-fixtures'
|
---|
| 75 | this.fixturesCache_ = {}
|
---|
| 76 | this.fixturesPath = 'spec/javascripts/fixtures'
|
---|
| 77 | }
|
---|
[0] | 78 |
|
---|
| 79 | jasmine.Fixtures.prototype.set = function(html) {
|
---|
[19] | 80 | this.cleanUp()
|
---|
| 81 | this.createContainer_(html)
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | jasmine.Fixtures.prototype.appendSet= function(html) {
|
---|
| 85 | this.addToContainer_(html)
|
---|
| 86 | }
|
---|
[0] | 87 |
|
---|
| 88 | jasmine.Fixtures.prototype.preload = function() {
|
---|
[19] | 89 | this.read.apply(this, arguments)
|
---|
| 90 | }
|
---|
[0] | 91 |
|
---|
| 92 | jasmine.Fixtures.prototype.load = function() {
|
---|
[19] | 93 | this.cleanUp()
|
---|
| 94 | this.createContainer_(this.read.apply(this, arguments))
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | jasmine.Fixtures.prototype.appendLoad = function() {
|
---|
| 98 | this.addToContainer_(this.read.apply(this, arguments))
|
---|
| 99 | }
|
---|
[0] | 100 |
|
---|
| 101 | jasmine.Fixtures.prototype.read = function() {
|
---|
[19] | 102 | var htmlChunks = []
|
---|
[0] | 103 |
|
---|
[19] | 104 | var fixtureUrls = arguments
|
---|
[0] | 105 | for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
|
---|
[19] | 106 | htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]))
|
---|
[0] | 107 | }
|
---|
| 108 |
|
---|
[19] | 109 | return htmlChunks.join('')
|
---|
| 110 | }
|
---|
[0] | 111 |
|
---|
| 112 | jasmine.Fixtures.prototype.clearCache = function() {
|
---|
[19] | 113 | this.fixturesCache_ = {}
|
---|
| 114 | }
|
---|
[0] | 115 |
|
---|
| 116 | jasmine.Fixtures.prototype.cleanUp = function() {
|
---|
[19] | 117 | $('#' + this.containerId).remove()
|
---|
| 118 | }
|
---|
[0] | 119 |
|
---|
| 120 | jasmine.Fixtures.prototype.sandbox = function(attributes) {
|
---|
[19] | 121 | var attributesToSet = attributes || {}
|
---|
| 122 | return $('<div id="sandbox" />').attr(attributesToSet)
|
---|
| 123 | }
|
---|
[0] | 124 |
|
---|
| 125 | jasmine.Fixtures.prototype.createContainer_ = function(html) {
|
---|
[19] | 126 | var container
|
---|
| 127 | if(html instanceof $) {
|
---|
| 128 | container = $('<div id="' + this.containerId + '" />')
|
---|
| 129 | container.html(html)
|
---|
[0] | 130 | } else {
|
---|
| 131 | container = '<div id="' + this.containerId + '">' + html + '</div>'
|
---|
| 132 | }
|
---|
[19] | 133 | $(document.body).append(container)
|
---|
| 134 | }
|
---|
[0] | 135 |
|
---|
[19] | 136 | jasmine.Fixtures.prototype.addToContainer_ = function(html){
|
---|
| 137 | var container = $(document.body).find('#'+this.containerId).append(html)
|
---|
| 138 | if(!container.length){
|
---|
| 139 | this.createContainer_(html)
|
---|
[0] | 140 | }
|
---|
[19] | 141 | }
|
---|
| 142 |
|
---|
| 143 | jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
|
---|
| 144 | if (typeof this.fixturesCache_[url] === 'undefined') {
|
---|
| 145 | this.loadFixtureIntoCache_(url)
|
---|
| 146 | }
|
---|
| 147 | return this.fixturesCache_[url]
|
---|
| 148 | }
|
---|
[0] | 149 |
|
---|
| 150 | jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
|
---|
[19] | 151 | var url = this.makeFixtureUrl_(relativeUrl)
|
---|
| 152 | var request = $.ajax({
|
---|
| 153 | type: "GET",
|
---|
| 154 | url: url + "?" + new Date().getTime(),
|
---|
| 155 | async: false
|
---|
| 156 | })
|
---|
| 157 | this.fixturesCache_[relativeUrl] = request.responseText
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | jasmine.Fixtures.prototype.makeFixtureUrl_ = function(relativeUrl){
|
---|
| 161 | return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
|
---|
| 165 | return this[methodName].apply(this, passedArguments)
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | jasmine.StyleFixtures = function() {
|
---|
| 170 | this.fixturesCache_ = {}
|
---|
| 171 | this.fixturesNodes_ = []
|
---|
| 172 | this.fixturesPath = 'spec/javascripts/fixtures'
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | jasmine.StyleFixtures.prototype.set = function(css) {
|
---|
| 176 | this.cleanUp()
|
---|
| 177 | this.createStyle_(css)
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | jasmine.StyleFixtures.prototype.appendSet = function(css) {
|
---|
| 181 | this.createStyle_(css)
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | jasmine.StyleFixtures.prototype.preload = function() {
|
---|
| 185 | this.read_.apply(this, arguments)
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | jasmine.StyleFixtures.prototype.load = function() {
|
---|
| 189 | this.cleanUp()
|
---|
| 190 | this.createStyle_(this.read_.apply(this, arguments))
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | jasmine.StyleFixtures.prototype.appendLoad = function() {
|
---|
| 194 | this.createStyle_(this.read_.apply(this, arguments))
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | jasmine.StyleFixtures.prototype.cleanUp = function() {
|
---|
| 198 | while(this.fixturesNodes_.length) {
|
---|
| 199 | this.fixturesNodes_.pop().remove()
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | jasmine.StyleFixtures.prototype.createStyle_ = function(html) {
|
---|
| 204 | var styleText = $('<div></div>').html(html).text(),
|
---|
| 205 | style = $('<style>' + styleText + '</style>')
|
---|
| 206 |
|
---|
| 207 | this.fixturesNodes_.push(style)
|
---|
| 208 |
|
---|
| 209 | $('head').append(style)
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache
|
---|
| 213 |
|
---|
| 214 | jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read
|
---|
| 215 |
|
---|
| 216 | jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_
|
---|
| 217 |
|
---|
| 218 | jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_
|
---|
| 219 |
|
---|
| 220 | jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_
|
---|
| 221 |
|
---|
| 222 | jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_
|
---|
| 223 |
|
---|
| 224 | jasmine.getJSONFixtures = function() {
|
---|
| 225 | return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures()
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | jasmine.JSONFixtures = function() {
|
---|
| 229 | this.fixturesCache_ = {}
|
---|
| 230 | this.fixturesPath = 'spec/javascripts/fixtures/json'
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | jasmine.JSONFixtures.prototype.load = function() {
|
---|
| 234 | this.read.apply(this, arguments)
|
---|
| 235 | return this.fixturesCache_
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | jasmine.JSONFixtures.prototype.read = function() {
|
---|
| 239 | var fixtureUrls = arguments
|
---|
| 240 | for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
|
---|
| 241 | this.getFixtureData_(fixtureUrls[urlIndex])
|
---|
| 242 | }
|
---|
| 243 | return this.fixturesCache_
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | jasmine.JSONFixtures.prototype.clearCache = function() {
|
---|
| 247 | this.fixturesCache_ = {}
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | jasmine.JSONFixtures.prototype.getFixtureData_ = function(url) {
|
---|
| 251 | this.loadFixtureIntoCache_(url)
|
---|
| 252 | return this.fixturesCache_[url]
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
|
---|
| 256 | var self = this
|
---|
| 257 | var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
|
---|
| 258 | $.ajax({
|
---|
[0] | 259 | async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
|
---|
| 260 | cache: false,
|
---|
[19] | 261 | dataType: 'json',
|
---|
[0] | 262 | url: url,
|
---|
| 263 | success: function(data) {
|
---|
[19] | 264 | self.fixturesCache_[relativeUrl] = data
|
---|
[0] | 265 | },
|
---|
[19] | 266 | fail: function(jqXHR, status, errorThrown) {
|
---|
| 267 | throw Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
|
---|
[0] | 268 | }
|
---|
[19] | 269 | })
|
---|
| 270 | }
|
---|
[0] | 271 |
|
---|
[19] | 272 | jasmine.JSONFixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
|
---|
| 273 | return this[methodName].apply(this, passedArguments)
|
---|
| 274 | }
|
---|
[0] | 275 |
|
---|
[19] | 276 | jasmine.JQuery = function() {}
|
---|
[0] | 277 |
|
---|
| 278 | jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
|
---|
[19] | 279 | return $('<div/>').append(html).html()
|
---|
| 280 | }
|
---|
[0] | 281 |
|
---|
| 282 | jasmine.JQuery.elementToString = function(element) {
|
---|
[19] | 283 | var domEl = $(element).get(0)
|
---|
| 284 | if (domEl == undefined || domEl.cloneNode)
|
---|
| 285 | return $('<div />').append($(element).clone()).html()
|
---|
| 286 | else
|
---|
| 287 | return element.toString()
|
---|
| 288 | }
|
---|
[0] | 289 |
|
---|
[19] | 290 | jasmine.JQuery.matchersClass = {}
|
---|
[0] | 291 |
|
---|
[19] | 292 | !function(namespace) {
|
---|
[0] | 293 | var data = {
|
---|
| 294 | spiedEvents: {},
|
---|
| 295 | handlers: []
|
---|
[19] | 296 | }
|
---|
[0] | 297 |
|
---|
| 298 | namespace.events = {
|
---|
| 299 | spyOn: function(selector, eventName) {
|
---|
| 300 | var handler = function(e) {
|
---|
[19] | 301 | data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = e
|
---|
| 302 | }
|
---|
| 303 | $(selector).bind(eventName, handler)
|
---|
| 304 | data.handlers.push(handler)
|
---|
| 305 | return {
|
---|
| 306 | selector: selector,
|
---|
| 307 | eventName: eventName,
|
---|
| 308 | handler: handler,
|
---|
| 309 | reset: function(){
|
---|
| 310 | delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
[0] | 313 | },
|
---|
| 314 |
|
---|
| 315 | wasTriggered: function(selector, eventName) {
|
---|
[19] | 316 | return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
|
---|
| 317 | },
|
---|
| 318 |
|
---|
| 319 | wasPrevented: function(selector, eventName) {
|
---|
| 320 | var e;
|
---|
| 321 | return (e = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]) && e.isDefaultPrevented()
|
---|
[0] | 322 | },
|
---|
| 323 |
|
---|
| 324 | cleanUp: function() {
|
---|
[19] | 325 | data.spiedEvents = {}
|
---|
| 326 | data.handlers = []
|
---|
[0] | 327 | }
|
---|
| 328 | }
|
---|
[19] | 329 | }(jasmine.JQuery)
|
---|
[0] | 330 |
|
---|
[19] | 331 | !function(){
|
---|
[0] | 332 | var jQueryMatchers = {
|
---|
| 333 | toHaveClass: function(className) {
|
---|
[19] | 334 | return this.actual.hasClass(className)
|
---|
| 335 | },
|
---|
| 336 |
|
---|
| 337 | toHaveCss: function(css){
|
---|
| 338 | for (var prop in css){
|
---|
| 339 | if (this.actual.css(prop) !== css[prop]) return false
|
---|
| 340 | }
|
---|
| 341 | return true
|
---|
[0] | 342 | },
|
---|
| 343 |
|
---|
| 344 | toBeVisible: function() {
|
---|
[19] | 345 | return this.actual.is(':visible')
|
---|
[0] | 346 | },
|
---|
| 347 |
|
---|
| 348 | toBeHidden: function() {
|
---|
[19] | 349 | return this.actual.is(':hidden')
|
---|
[0] | 350 | },
|
---|
| 351 |
|
---|
| 352 | toBeSelected: function() {
|
---|
[19] | 353 | return this.actual.is(':selected')
|
---|
[0] | 354 | },
|
---|
| 355 |
|
---|
| 356 | toBeChecked: function() {
|
---|
[19] | 357 | return this.actual.is(':checked')
|
---|
[0] | 358 | },
|
---|
| 359 |
|
---|
| 360 | toBeEmpty: function() {
|
---|
[19] | 361 | return this.actual.is(':empty')
|
---|
[0] | 362 | },
|
---|
| 363 |
|
---|
| 364 | toExist: function() {
|
---|
[19] | 365 | return $(document).find(this.actual).length
|
---|
| 366 | },
|
---|
| 367 |
|
---|
| 368 | toHaveLength: function(length) {
|
---|
| 369 | return this.actual.length === length
|
---|
[0] | 370 | },
|
---|
| 371 |
|
---|
| 372 | toHaveAttr: function(attributeName, expectedAttributeValue) {
|
---|
[19] | 373 | return hasProperty(this.actual.attr(attributeName), expectedAttributeValue)
|
---|
| 374 | },
|
---|
| 375 |
|
---|
| 376 | toHaveProp: function(propertyName, expectedPropertyValue) {
|
---|
| 377 | return hasProperty(this.actual.prop(propertyName), expectedPropertyValue)
|
---|
[0] | 378 | },
|
---|
| 379 |
|
---|
| 380 | toHaveId: function(id) {
|
---|
[19] | 381 | return this.actual.attr('id') == id
|
---|
[0] | 382 | },
|
---|
| 383 |
|
---|
| 384 | toHaveHtml: function(html) {
|
---|
[19] | 385 | return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html)
|
---|
| 386 | },
|
---|
| 387 |
|
---|
| 388 | toContainHtml: function(html){
|
---|
| 389 | var actualHtml = this.actual.html()
|
---|
| 390 | var expectedHtml = jasmine.JQuery.browserTagCaseIndependentHtml(html)
|
---|
| 391 | return (actualHtml.indexOf(expectedHtml) >= 0)
|
---|
[0] | 392 | },
|
---|
| 393 |
|
---|
| 394 | toHaveText: function(text) {
|
---|
[19] | 395 | var trimmedText = $.trim(this.actual.text())
|
---|
| 396 | if (text && $.isFunction(text.test)) {
|
---|
| 397 | return text.test(trimmedText)
|
---|
[0] | 398 | } else {
|
---|
[19] | 399 | return trimmedText == text
|
---|
[0] | 400 | }
|
---|
| 401 | },
|
---|
| 402 |
|
---|
| 403 | toHaveValue: function(value) {
|
---|
[19] | 404 | return this.actual.val() === value
|
---|
[0] | 405 | },
|
---|
| 406 |
|
---|
| 407 | toHaveData: function(key, expectedValue) {
|
---|
[19] | 408 | return hasProperty(this.actual.data(key), expectedValue)
|
---|
[0] | 409 | },
|
---|
| 410 |
|
---|
| 411 | toBe: function(selector) {
|
---|
[19] | 412 | return this.actual.is(selector)
|
---|
[0] | 413 | },
|
---|
| 414 |
|
---|
| 415 | toContain: function(selector) {
|
---|
[19] | 416 | return this.actual.find(selector).length
|
---|
[0] | 417 | },
|
---|
| 418 |
|
---|
| 419 | toBeDisabled: function(selector){
|
---|
[19] | 420 | return this.actual.is(':disabled')
|
---|
| 421 | },
|
---|
| 422 |
|
---|
| 423 | toBeFocused: function(selector) {
|
---|
| 424 | return this.actual[0] === this.actual[0].ownerDocument.activeElement
|
---|
[0] | 425 | },
|
---|
| 426 |
|
---|
[19] | 427 | toHandle: function(event) {
|
---|
| 428 |
|
---|
| 429 | var events = $._data(this.actual.get(0), "events")
|
---|
| 430 |
|
---|
| 431 | if(!events || !event || typeof event !== "string") {
|
---|
| 432 | return false
|
---|
| 433 | }
|
---|
| 434 |
|
---|
| 435 | var namespaces = event.split(".")
|
---|
| 436 | var eventType = namespaces.shift()
|
---|
| 437 | var sortedNamespaces = namespaces.slice(0).sort()
|
---|
| 438 | var namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
|
---|
| 439 |
|
---|
| 440 | if(events[eventType] && namespaces.length) {
|
---|
| 441 | for(var i = 0; i < events[eventType].length; i++) {
|
---|
| 442 | var namespace = events[eventType][i].namespace
|
---|
| 443 | if(namespaceRegExp.test(namespace)) {
|
---|
| 444 | return true
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
| 447 | } else {
|
---|
| 448 | return events[eventType] && events[eventType].length > 0
|
---|
| 449 | }
|
---|
[0] | 450 | },
|
---|
[19] | 451 |
|
---|
[0] | 452 | // tests the existence of a specific event binding + handler
|
---|
| 453 | toHandleWith: function(eventName, eventHandler) {
|
---|
[19] | 454 | var stack = $._data(this.actual.get(0), "events")[eventName]
|
---|
| 455 | for (var i = 0; i < stack.length; i++) {
|
---|
| 456 | if (stack[i].handler == eventHandler) return true
|
---|
[0] | 457 | }
|
---|
[19] | 458 | return false
|
---|
[0] | 459 | }
|
---|
[19] | 460 | }
|
---|
[0] | 461 |
|
---|
| 462 | var hasProperty = function(actualValue, expectedValue) {
|
---|
[19] | 463 | if (expectedValue === undefined) return actualValue !== undefined
|
---|
| 464 | return actualValue == expectedValue
|
---|
| 465 | }
|
---|
[0] | 466 |
|
---|
| 467 | var bindMatcher = function(methodName) {
|
---|
[19] | 468 | var builtInMatcher = jasmine.Matchers.prototype[methodName]
|
---|
[0] | 469 |
|
---|
| 470 | jasmine.JQuery.matchersClass[methodName] = function() {
|
---|
[19] | 471 | if (this.actual
|
---|
| 472 | && (this.actual instanceof $
|
---|
| 473 | || jasmine.isDomNode(this.actual))) {
|
---|
| 474 | this.actual = $(this.actual)
|
---|
| 475 | var result = jQueryMatchers[methodName].apply(this, arguments)
|
---|
| 476 | var element
|
---|
| 477 | if (this.actual.get && (element = this.actual.get()[0]) && !$.isWindow(element) && element.tagName !== "HTML")
|
---|
| 478 | this.actual = jasmine.JQuery.elementToString(this.actual)
|
---|
| 479 | return result
|
---|
| 480 | }
|
---|
[0] | 481 |
|
---|
[19] | 482 | if (builtInMatcher) {
|
---|
| 483 | return builtInMatcher.apply(this, arguments)
|
---|
| 484 | }
|
---|
[0] | 485 |
|
---|
[19] | 486 | return false
|
---|
| 487 | }
|
---|
| 488 | }
|
---|
[0] | 489 |
|
---|
| 490 | for(var methodName in jQueryMatchers) {
|
---|
[19] | 491 | bindMatcher(methodName)
|
---|
[0] | 492 | }
|
---|
[19] | 493 | }()
|
---|
[0] | 494 |
|
---|
| 495 | beforeEach(function() {
|
---|
[19] | 496 | this.addMatchers(jasmine.JQuery.matchersClass)
|
---|
[0] | 497 | this.addMatchers({
|
---|
| 498 | toHaveBeenTriggeredOn: function(selector) {
|
---|
| 499 | this.message = function() {
|
---|
| 500 | return [
|
---|
[19] | 501 | "Expected event " + this.actual + " to have been triggered on " + selector,
|
---|
| 502 | "Expected event " + this.actual + " not to have been triggered on " + selector
|
---|
| 503 | ]
|
---|
| 504 | }
|
---|
| 505 | return jasmine.JQuery.events.wasTriggered(selector, this.actual)
|
---|
[0] | 506 | }
|
---|
| 507 | })
|
---|
[19] | 508 | this.addMatchers({
|
---|
| 509 | toHaveBeenTriggered: function(){
|
---|
| 510 | var eventName = this.actual.eventName,
|
---|
| 511 | selector = this.actual.selector
|
---|
| 512 | this.message = function() {
|
---|
| 513 | return [
|
---|
| 514 | "Expected event " + eventName + " to have been triggered on " + selector,
|
---|
| 515 | "Expected event " + eventName + " not to have been triggered on " + selector
|
---|
| 516 | ]
|
---|
| 517 | }
|
---|
| 518 | return jasmine.JQuery.events.wasTriggered(selector, eventName)
|
---|
| 519 | }
|
---|
| 520 | })
|
---|
| 521 | this.addMatchers({
|
---|
| 522 | toHaveBeenPreventedOn: function(selector) {
|
---|
| 523 | this.message = function() {
|
---|
| 524 | return [
|
---|
| 525 | "Expected event " + this.actual + " to have been prevented on " + selector,
|
---|
| 526 | "Expected event " + this.actual + " not to have been prevented on " + selector
|
---|
| 527 | ]
|
---|
| 528 | }
|
---|
| 529 | return jasmine.JQuery.events.wasPrevented(selector, this.actual)
|
---|
| 530 | }
|
---|
| 531 | })
|
---|
| 532 | this.addMatchers({
|
---|
| 533 | toHaveBeenPrevented: function() {
|
---|
| 534 | var eventName = this.actual.eventName,
|
---|
| 535 | selector = this.actual.selector
|
---|
| 536 | this.message = function() {
|
---|
| 537 | return [
|
---|
| 538 | "Expected event " + eventName + " to have been prevented on " + selector,
|
---|
| 539 | "Expected event " + eventName + " not to have been prevented on " + selector
|
---|
| 540 | ]
|
---|
| 541 | }
|
---|
| 542 | return jasmine.JQuery.events.wasPrevented(selector, eventName)
|
---|
| 543 | }
|
---|
| 544 | })
|
---|
| 545 | })
|
---|
[0] | 546 |
|
---|
| 547 | afterEach(function() {
|
---|
[19] | 548 | jasmine.getFixtures().cleanUp()
|
---|
| 549 | jasmine.getStyleFixtures().cleanUp()
|
---|
| 550 | jasmine.JQuery.events.cleanUp()
|
---|
| 551 | })
|
---|