corrade-nucleus-nucleons – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /*!
|
2 | Jasmine-jQuery: a set of jQuery helpers for Jasmine tests.
|
||
3 | |||
4 | Version 2.0.5
|
||
5 | |||
6 | https://github.com/velesin/jasmine-jquery
|
||
7 | |||
8 | Copyright (c) 2010-2014 Wojciech Zawistowski, Travis Jeffery
|
||
9 | |||
10 | Permission is hereby granted, free of charge, to any person obtaining
|
||
11 | a copy of this software and associated documentation files (the
|
||
12 | "Software"), to deal in the Software without restriction, including
|
||
13 | without limitation the rights to use, copy, modify, merge, publish,
|
||
14 | distribute, sublicense, and/or sell copies of the Software, and to
|
||
15 | permit persons to whom the Software is furnished to do so, subject to
|
||
16 | the following conditions:
|
||
17 | |||
18 | The above copyright notice and this permission notice shall be
|
||
19 | included in all copies or substantial portions of the Software.
|
||
20 | |||
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
22 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||
23 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||
24 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||
25 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||
26 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||
27 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||
28 | */ |
||
29 | |||
30 | +function (window, jasmine, $) { "use strict"; |
||
31 | |||
32 | jasmine.spiedEventsKey = function (selector, eventName) { |
||
33 | return [$(selector).selector, eventName].toString() |
||
34 | } |
||
35 | |||
36 | jasmine.getFixtures = function () { |
||
37 | return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures() |
||
38 | } |
||
39 | |||
40 | jasmine.getStyleFixtures = function () { |
||
41 | return jasmine.currentStyleFixtures_ = jasmine.currentStyleFixtures_ || new jasmine.StyleFixtures() |
||
42 | } |
||
43 | |||
44 | jasmine.Fixtures = function () { |
||
45 | this.containerId = 'jasmine-fixtures' |
||
46 | this.fixturesCache_ = {} |
||
47 | this.fixturesPath = 'spec/javascripts/fixtures' |
||
48 | } |
||
49 | |||
50 | jasmine.setFixturesPath = function(fixturesPath){ |
||
51 | jasmine.Fixtures.fixturesPath = fixturesPath; |
||
52 | } |
||
53 | |||
54 | jasmine.Fixtures.prototype.set = function (html) { |
||
55 | this.cleanUp() |
||
56 | return this.createContainer_(html) |
||
57 | } |
||
58 | |||
59 | jasmine.Fixtures.prototype.appendSet= function (html) { |
||
60 | this.addToContainer_(html) |
||
61 | } |
||
62 | |||
63 | jasmine.Fixtures.prototype.preload = function () { |
||
64 | this.read.apply(this, arguments) |
||
65 | } |
||
66 | |||
67 | jasmine.Fixtures.prototype.load = function () { |
||
68 | this.cleanUp() |
||
69 | this.createContainer_(this.read.apply(this, arguments)) |
||
70 | } |
||
71 | |||
72 | jasmine.Fixtures.prototype.appendLoad = function () { |
||
73 | this.addToContainer_(this.read.apply(this, arguments)) |
||
74 | } |
||
75 | |||
76 | jasmine.Fixtures.prototype.read = function () { |
||
77 | var htmlChunks = [] |
||
78 | , fixtureUrls = arguments |
||
79 | |||
80 | for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) { |
||
81 | htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex])) |
||
82 | } |
||
83 | |||
84 | return htmlChunks.join('') |
||
85 | } |
||
86 | |||
87 | jasmine.Fixtures.prototype.clearCache = function () { |
||
88 | this.fixturesCache_ = {} |
||
89 | } |
||
90 | |||
91 | jasmine.Fixtures.prototype.cleanUp = function () { |
||
92 | $('#' + this.containerId).remove() |
||
93 | } |
||
94 | |||
95 | jasmine.Fixtures.prototype.sandbox = function (attributes) { |
||
96 | var attributesToSet = attributes || {} |
||
97 | return $('<div id="sandbox" />').attr(attributesToSet) |
||
98 | } |
||
99 | |||
100 | jasmine.Fixtures.prototype.createContainer_ = function (html) { |
||
101 | var container = $('<div>') |
||
102 | .attr('id', this.containerId) |
||
103 | .html(html) |
||
104 | |||
105 | $(document.body).append(container) |
||
106 | return container |
||
107 | } |
||
108 | |||
109 | jasmine.Fixtures.prototype.addToContainer_ = function (html){ |
||
110 | var container = $(document.body).find('#'+this.containerId).append(html) |
||
111 | |||
112 | if (!container.length) { |
||
113 | this.createContainer_(html) |
||
114 | } |
||
115 | } |
||
116 | |||
117 | jasmine.Fixtures.prototype.getFixtureHtml_ = function (url) { |
||
118 | if (typeof this.fixturesCache_[url] === 'undefined') { |
||
119 | this.loadFixtureIntoCache_(url) |
||
120 | } |
||
121 | return this.fixturesCache_[url] |
||
122 | } |
||
123 | |||
124 | jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) { |
||
125 | var self = this |
||
126 | , url = this.makeFixtureUrl_(relativeUrl) |
||
127 | , htmlText = '' |
||
128 | , request = $.ajax({ |
||
129 | async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
|
||
130 | cache: false, |
||
131 | url: url, |
||
132 | success: function (data, status, $xhr) { |
||
133 | htmlText = $xhr.responseText |
||
134 | } |
||
135 | }).fail(function ($xhr, status, err) { |
||
136 | throw new Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')') |
||
137 | }) |
||
138 | |||
139 | var scripts = $($.parseHTML(htmlText, true)).find('script[src]') || []; |
||
140 | |||
141 | scripts.each(function(){ |
||
142 | $.ajax({ |
||
143 | async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
|
||
144 | cache: false, |
||
145 | dataType: 'script', |
||
146 | url: $(this).attr('src'), |
||
147 | success: function (data, status, $xhr) { |
||
148 | htmlText += '<script>' + $xhr.responseText + '</script>' |
||
149 | }, |
||
150 | error: function ($xhr, status, err) { |
||
151 | throw new Error('Script could not be loaded: ' + scriptSrc + ' (status: ' + status + ', message: ' + err.message + ')') |
||
152 | } |
||
153 | }); |
||
154 | }) |
||
155 | |||
156 | self.fixturesCache_[relativeUrl] = htmlText; |
||
157 | } |
||
158 | |||
159 | jasmine.Fixtures.prototype.makeFixtureUrl_ = function (relativeUrl){ |
||
160 | return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl |
||
161 | } |
||
162 | |||
163 | jasmine.Fixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) { |
||
164 | return this[methodName].apply(this, passedArguments) |
||
165 | } |
||
166 | |||
167 | |||
168 | jasmine.StyleFixtures = function () { |
||
169 | this.fixturesCache_ = {} |
||
170 | this.fixturesNodes_ = [] |
||
171 | this.fixturesPath = 'spec/javascripts/fixtures' |
||
172 | } |
||
173 | |||
174 | jasmine.StyleFixtures.prototype.set = function (css) { |
||
175 | this.cleanUp() |
||
176 | this.createStyle_(css) |
||
177 | } |
||
178 | |||
179 | jasmine.StyleFixtures.prototype.appendSet = function (css) { |
||
180 | this.createStyle_(css) |
||
181 | } |
||
182 | |||
183 | jasmine.StyleFixtures.prototype.preload = function () { |
||
184 | this.read_.apply(this, arguments) |
||
185 | } |
||
186 | |||
187 | jasmine.StyleFixtures.prototype.load = function () { |
||
188 | this.cleanUp() |
||
189 | this.createStyle_(this.read_.apply(this, arguments)) |
||
190 | } |
||
191 | |||
192 | jasmine.StyleFixtures.prototype.appendLoad = function () { |
||
193 | this.createStyle_(this.read_.apply(this, arguments)) |
||
194 | } |
||
195 | |||
196 | jasmine.StyleFixtures.prototype.cleanUp = function () { |
||
197 | while(this.fixturesNodes_.length) { |
||
198 | this.fixturesNodes_.pop().remove() |
||
199 | } |
||
200 | } |
||
201 | |||
202 | jasmine.StyleFixtures.prototype.createStyle_ = function (html) { |
||
203 | var styleText = $('<div></div>').html(html).text() |
||
204 | , style = $('<style>' + styleText + '</style>') |
||
205 | |||
206 | this.fixturesNodes_.push(style) |
||
207 | $('head').append(style) |
||
208 | } |
||
209 | |||
210 | jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache |
||
211 | jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read |
||
212 | jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_ |
||
213 | jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_ |
||
214 | jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_ |
||
215 | jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_ |
||
216 | |||
217 | jasmine.getJSONFixtures = function () { |
||
218 | return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures() |
||
219 | } |
||
220 | |||
221 | jasmine.JSONFixtures = function () { |
||
222 | this.fixturesCache_ = {} |
||
223 | this.fixturesPath = 'spec/javascripts/fixtures/json' |
||
224 | } |
||
225 | |||
226 | jasmine.JSONFixtures.prototype.load = function () { |
||
227 | this.read.apply(this, arguments) |
||
228 | return this.fixturesCache_ |
||
229 | } |
||
230 | |||
231 | jasmine.JSONFixtures.prototype.read = function () { |
||
232 | var fixtureUrls = arguments |
||
233 | |||
234 | for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) { |
||
235 | this.getFixtureData_(fixtureUrls[urlIndex]) |
||
236 | } |
||
237 | |||
238 | return this.fixturesCache_ |
||
239 | } |
||
240 | |||
241 | jasmine.JSONFixtures.prototype.clearCache = function () { |
||
242 | this.fixturesCache_ = {} |
||
243 | } |
||
244 | |||
245 | jasmine.JSONFixtures.prototype.getFixtureData_ = function (url) { |
||
246 | if (!this.fixturesCache_[url]) this.loadFixtureIntoCache_(url) |
||
247 | return this.fixturesCache_[url] |
||
248 | } |
||
249 | |||
250 | jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) { |
||
251 | var self = this |
||
252 | , url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl |
||
253 | |||
254 | $.ajax({ |
||
255 | async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
|
||
256 | cache: false, |
||
257 | dataType: 'json', |
||
258 | url: url, |
||
259 | success: function (data) { |
||
260 | self.fixturesCache_[relativeUrl] = data |
||
261 | }, |
||
262 | error: function ($xhr, status, err) { |
||
263 | throw new Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')') |
||
264 | } |
||
265 | }) |
||
266 | } |
||
267 | |||
268 | jasmine.JSONFixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) { |
||
269 | return this[methodName].apply(this, passedArguments) |
||
270 | } |
||
271 | |||
272 | jasmine.jQuery = function () {} |
||
273 | |||
274 | jasmine.jQuery.browserTagCaseIndependentHtml = function (html) { |
||
275 | return $('<div/>').append(html).html() |
||
276 | } |
||
277 | |||
278 | jasmine.jQuery.elementToString = function (element) { |
||
279 | return $(element).map(function () { return this.outerHTML; }).toArray().join(', ') |
||
280 | } |
||
281 | |||
282 | var data = { |
||
283 | spiedEvents: {} |
||
284 | , handlers: [] |
||
285 | } |
||
286 | |||
287 | jasmine.jQuery.events = { |
||
288 | spyOn: function (selector, eventName) { |
||
289 | var handler = function (e) { |
||
290 | data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = jasmine.util.argsToArray(arguments) |
||
291 | } |
||
292 | |||
293 | $(selector).on(eventName, handler) |
||
294 | data.handlers.push(handler) |
||
295 | |||
296 | return { |
||
297 | selector: selector, |
||
298 | eventName: eventName, |
||
299 | handler: handler, |
||
300 | reset: function (){ |
||
301 | delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] |
||
302 | } |
||
303 | } |
||
304 | }, |
||
305 | |||
306 | args: function (selector, eventName) { |
||
307 | var actualArgs = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] |
||
308 | |||
309 | if (!actualArgs) { |
||
310 | throw "There is no spy for " + eventName + " on " + selector.toString() + ". Make sure to create a spy using spyOnEvent." |
||
311 | } |
||
312 | |||
313 | return actualArgs |
||
314 | }, |
||
315 | |||
316 | wasTriggered: function (selector, eventName) { |
||
317 | return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]) |
||
318 | }, |
||
319 | |||
320 | wasTriggeredWith: function (selector, eventName, expectedArgs, util, customEqualityTesters) { |
||
321 | var actualArgs = jasmine.jQuery.events.args(selector, eventName).slice(1) |
||
322 | |||
323 | if (Object.prototype.toString.call(expectedArgs) !== '[object Array]') |
||
324 | actualArgs = actualArgs[0] |
||
325 | |||
326 | return util.equals(expectedArgs, actualArgs, customEqualityTesters) |
||
327 | }, |
||
328 | |||
329 | wasPrevented: function (selector, eventName) { |
||
330 | var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] |
||
331 | , e = args ? args[0] : undefined |
||
332 | |||
333 | return e && e.isDefaultPrevented() |
||
334 | }, |
||
335 | |||
336 | wasStopped: function (selector, eventName) { |
||
337 | var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] |
||
338 | , e = args ? args[0] : undefined |
||
339 | return e && e.isPropagationStopped() |
||
340 | }, |
||
341 | |||
342 | cleanUp: function () { |
||
343 | data.spiedEvents = {} |
||
344 | data.handlers = [] |
||
345 | } |
||
346 | } |
||
347 | |||
348 | var hasProperty = function (actualValue, expectedValue) { |
||
349 | if (expectedValue === undefined) |
||
350 | return actualValue !== undefined |
||
351 | |||
352 | return actualValue === expectedValue |
||
353 | } |
||
354 | |||
355 | beforeEach(function () { |
||
356 | jasmine.addMatchers({ |
||
357 | toHaveClass: function () { |
||
358 | return { |
||
359 | compare: function (actual, className) { |
||
360 | return { pass: $(actual).hasClass(className) } |
||
361 | } |
||
362 | } |
||
363 | }, |
||
364 | |||
365 | toHaveCss: function () { |
||
366 | return { |
||
367 | compare: function (actual, css) { |
||
368 | for (var prop in css){ |
||
369 | var value = css[prop] |
||
370 | // see issue #147 on gh
|
||
371 | ;if (value === 'auto' && $(actual).get(0).style[prop] === 'auto') continue |
||
372 | if ($(actual).css(prop) !== value) return { pass: false } |
||
373 | } |
||
374 | return { pass: true } |
||
375 | } |
||
376 | } |
||
377 | }, |
||
378 | |||
379 | toBeVisible: function () { |
||
380 | return { |
||
381 | compare: function (actual) { |
||
382 | return { pass: $(actual).is(':visible') } |
||
383 | } |
||
384 | } |
||
385 | }, |
||
386 | |||
387 | toBeHidden: function () { |
||
388 | return { |
||
389 | compare: function (actual) { |
||
390 | return { pass: $(actual).is(':hidden') } |
||
391 | } |
||
392 | } |
||
393 | }, |
||
394 | |||
395 | toBeSelected: function () { |
||
396 | return { |
||
397 | compare: function (actual) { |
||
398 | return { pass: $(actual).is(':selected') } |
||
399 | } |
||
400 | } |
||
401 | }, |
||
402 | |||
403 | toBeChecked: function () { |
||
404 | return { |
||
405 | compare: function (actual) { |
||
406 | return { pass: $(actual).is(':checked') } |
||
407 | } |
||
408 | } |
||
409 | }, |
||
410 | |||
411 | toBeEmpty: function () { |
||
412 | return { |
||
413 | compare: function (actual) { |
||
414 | return { pass: $(actual).is(':empty') } |
||
415 | } |
||
416 | } |
||
417 | }, |
||
418 | |||
419 | toBeInDOM: function () { |
||
420 | return { |
||
421 | compare: function (actual) { |
||
422 | return { pass: $.contains(document.documentElement, $(actual)[0]) } |
||
423 | } |
||
424 | } |
||
425 | }, |
||
426 | |||
427 | toExist: function () { |
||
428 | return { |
||
429 | compare: function (actual) { |
||
430 | return { pass: $(actual).length } |
||
431 | } |
||
432 | } |
||
433 | }, |
||
434 | |||
435 | toHaveLength: function () { |
||
436 | return { |
||
437 | compare: function (actual, length) { |
||
438 | return { pass: $(actual).length === length } |
||
439 | } |
||
440 | } |
||
441 | }, |
||
442 | |||
443 | toHaveAttr: function () { |
||
444 | return { |
||
445 | compare: function (actual, attributeName, expectedAttributeValue) { |
||
446 | return { pass: hasProperty($(actual).attr(attributeName), expectedAttributeValue) } |
||
447 | } |
||
448 | } |
||
449 | }, |
||
450 | |||
451 | toHaveProp: function () { |
||
452 | return { |
||
453 | compare: function (actual, propertyName, expectedPropertyValue) { |
||
454 | return { pass: hasProperty($(actual).prop(propertyName), expectedPropertyValue) } |
||
455 | } |
||
456 | } |
||
457 | }, |
||
458 | |||
459 | toHaveId: function () { |
||
460 | return { |
||
461 | compare: function (actual, id) { |
||
462 | return { pass: $(actual).attr('id') == id } |
||
463 | } |
||
464 | } |
||
465 | }, |
||
466 | |||
467 | toHaveHtml: function () { |
||
468 | return { |
||
469 | compare: function (actual, html) { |
||
470 | return { pass: $(actual).html() == jasmine.jQuery.browserTagCaseIndependentHtml(html) } |
||
471 | } |
||
472 | } |
||
473 | }, |
||
474 | |||
475 | toContainHtml: function () { |
||
476 | return { |
||
477 | compare: function (actual, html) { |
||
478 | var actualHtml = $(actual).html() |
||
479 | , expectedHtml = jasmine.jQuery.browserTagCaseIndependentHtml(html) |
||
480 | |||
481 | return { pass: (actualHtml.indexOf(expectedHtml) >= 0) } |
||
482 | } |
||
483 | } |
||
484 | }, |
||
485 | |||
486 | toHaveText: function () { |
||
487 | return { |
||
488 | compare: function (actual, text) { |
||
489 | var actualText = $(actual).text() |
||
490 | var trimmedText = $.trim(actualText) |
||
491 | |||
492 | if (text && $.isFunction(text.test)) { |
||
493 | return { pass: text.test(actualText) || text.test(trimmedText) } |
||
494 | } else { |
||
495 | return { pass: (actualText == text || trimmedText == text) } |
||
496 | } |
||
497 | } |
||
498 | } |
||
499 | }, |
||
500 | |||
501 | toContainText: function () { |
||
502 | return { |
||
503 | compare: function (actual, text) { |
||
504 | var trimmedText = $.trim($(actual).text()) |
||
505 | |||
506 | if (text && $.isFunction(text.test)) { |
||
507 | return { pass: text.test(trimmedText) } |
||
508 | } else { |
||
509 | return { pass: trimmedText.indexOf(text) != -1 } |
||
510 | } |
||
511 | } |
||
512 | } |
||
513 | }, |
||
514 | |||
515 | toHaveValue: function () { |
||
516 | return { |
||
517 | compare: function (actual, value) { |
||
518 | return { pass: $(actual).val() === value } |
||
519 | } |
||
520 | } |
||
521 | }, |
||
522 | |||
523 | toHaveData: function () { |
||
524 | return { |
||
525 | compare: function (actual, key, expectedValue) { |
||
526 | return { pass: hasProperty($(actual).data(key), expectedValue) } |
||
527 | } |
||
528 | } |
||
529 | }, |
||
530 | |||
531 | toContainElement: function () { |
||
532 | return { |
||
533 | compare: function (actual, selector) { |
||
534 | if (window.debug) debugger |
||
535 | return { pass: $(actual).find(selector).length } |
||
536 | } |
||
537 | } |
||
538 | }, |
||
539 | |||
540 | toBeMatchedBy: function () { |
||
541 | return { |
||
542 | compare: function (actual, selector) { |
||
543 | return { pass: $(actual).filter(selector).length } |
||
544 | } |
||
545 | } |
||
546 | }, |
||
547 | |||
548 | toBeDisabled: function () { |
||
549 | return { |
||
550 | compare: function (actual, selector) { |
||
551 | return { pass: $(actual).is(':disabled') } |
||
552 | } |
||
553 | } |
||
554 | }, |
||
555 | |||
556 | toBeFocused: function (selector) { |
||
557 | return { |
||
558 | compare: function (actual, selector) { |
||
559 | return { pass: $(actual)[0] === $(actual)[0].ownerDocument.activeElement } |
||
560 | } |
||
561 | } |
||
562 | }, |
||
563 | |||
564 | toHandle: function () { |
||
565 | return { |
||
566 | compare: function (actual, event) { |
||
567 | var events = $._data($(actual).get(0), "events") |
||
568 | |||
569 | if (!events || !event || typeof event !== "string") { |
||
570 | return { pass: false } |
||
571 | } |
||
572 | |||
573 | var namespaces = event.split(".") |
||
574 | , eventType = namespaces.shift() |
||
575 | , sortedNamespaces = namespaces.slice(0).sort() |
||
576 | , namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)") |
||
577 | |||
578 | if (events[eventType] && namespaces.length) { |
||
579 | for (var i = 0; i < events[eventType].length; i++) { |
||
580 | var namespace = events[eventType][i].namespace |
||
581 | |||
582 | if (namespaceRegExp.test(namespace)) |
||
583 | return { pass: true } |
||
584 | } |
||
585 | } else { |
||
586 | return { pass: (events[eventType] && events[eventType].length > 0) } |
||
587 | } |
||
588 | |||
589 | return { pass: false } |
||
590 | } |
||
591 | } |
||
592 | }, |
||
593 | |||
594 | toHandleWith: function () { |
||
595 | return { |
||
596 | compare: function (actual, eventName, eventHandler) { |
||
597 | var normalizedEventName = eventName.split('.')[0] |
||
598 | , stack = $._data($(actual).get(0), "events")[normalizedEventName] |
||
599 | |||
600 | for (var i = 0; i < stack.length; i++) { |
||
601 | if (stack[i].handler == eventHandler) return { pass: true } |
||
602 | } |
||
603 | |||
604 | return { pass: false } |
||
605 | } |
||
606 | } |
||
607 | }, |
||
608 | |||
609 | toHaveBeenTriggeredOn: function () { |
||
610 | return { |
||
611 | compare: function (actual, selector) { |
||
612 | var result = { pass: jasmine.jQuery.events.wasTriggered(selector, actual) } |
||
613 | |||
614 | result.message = result.pass ? |
||
615 | "Expected event " + $(actual) + " not to have been triggered on " + selector : |
||
616 | "Expected event " + $(actual) + " to have been triggered on " + selector |
||
617 | |||
618 | return result; |
||
619 | } |
||
620 | } |
||
621 | }, |
||
622 | |||
623 | toHaveBeenTriggered: function (){ |
||
624 | return { |
||
625 | compare: function (actual) { |
||
626 | var eventName = actual.eventName |
||
627 | , selector = actual.selector |
||
628 | , result = { pass: jasmine.jQuery.events.wasTriggered(selector, eventName) } |
||
629 | |||
630 | result.message = result.pass ? |
||
631 | "Expected event " + eventName + " not to have been triggered on " + selector : |
||
632 | "Expected event " + eventName + " to have been triggered on " + selector |
||
633 | |||
634 | return result |
||
635 | } |
||
636 | } |
||
637 | }, |
||
638 | |||
639 | toHaveBeenTriggeredOnAndWith: function (j$, customEqualityTesters) { |
||
640 | return { |
||
641 | compare: function (actual, selector, expectedArgs) { |
||
642 | var wasTriggered = jasmine.jQuery.events.wasTriggered(selector, actual) |
||
643 | , result = { pass: wasTriggered && jasmine.jQuery.events.wasTriggeredWith(selector, actual, expectedArgs, j$, customEqualityTesters) } |
||
644 | |||
645 | if (wasTriggered) { |
||
646 | var actualArgs = jasmine.jQuery.events.args(selector, actual, expectedArgs)[1] |
||
647 | result.message = result.pass ? |
||
648 | "Expected event " + actual + " not to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs) : |
||
649 | "Expected event " + actual + " to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs) |
||
650 | |||
651 | } else { |
||
652 | // todo check on this
|
||
653 | result.message = result.pass ? |
||
654 | "Expected event " + actual + " not to have been triggered on " + selector : |
||
655 | "Expected event " + actual + " to have been triggered on " + selector |
||
656 | } |
||
657 | |||
658 | return result |
||
659 | } |
||
660 | } |
||
661 | }, |
||
662 | |||
663 | toHaveBeenPreventedOn: function () { |
||
664 | return { |
||
665 | compare: function (actual, selector) { |
||
666 | var result = { pass: jasmine.jQuery.events.wasPrevented(selector, actual) } |
||
667 | |||
668 | result.message = result.pass ? |
||
669 | "Expected event " + actual + " not to have been prevented on " + selector : |
||
670 | "Expected event " + actual + " to have been prevented on " + selector |
||
671 | |||
672 | return result |
||
673 | } |
||
674 | } |
||
675 | }, |
||
676 | |||
677 | toHaveBeenPrevented: function () { |
||
678 | return { |
||
679 | compare: function (actual) { |
||
680 | var eventName = actual.eventName |
||
681 | , selector = actual.selector |
||
682 | , result = { pass: jasmine.jQuery.events.wasPrevented(selector, eventName) } |
||
683 | |||
684 | result.message = result.pass ? |
||
685 | "Expected event " + eventName + " not to have been prevented on " + selector : |
||
686 | "Expected event " + eventName + " to have been prevented on " + selector |
||
687 | |||
688 | return result |
||
689 | } |
||
690 | } |
||
691 | }, |
||
692 | |||
693 | toHaveBeenStoppedOn: function () { |
||
694 | return { |
||
695 | compare: function (actual, selector) { |
||
696 | var result = { pass: jasmine.jQuery.events.wasStopped(selector, actual) } |
||
697 | |||
698 | result.message = result.pass ? |
||
699 | "Expected event " + actual + " not to have been stopped on " + selector : |
||
700 | "Expected event " + actual + " to have been stopped on " + selector |
||
701 | |||
702 | return result; |
||
703 | } |
||
704 | } |
||
705 | }, |
||
706 | |||
707 | toHaveBeenStopped: function () { |
||
708 | return { |
||
709 | compare: function (actual) { |
||
710 | var eventName = actual.eventName |
||
711 | , selector = actual.selector |
||
712 | , result = { pass: jasmine.jQuery.events.wasStopped(selector, eventName) } |
||
713 | |||
714 | result.message = result.pass ? |
||
715 | "Expected event " + eventName + " not to have been stopped on " + selector : |
||
716 | "Expected event " + eventName + " to have been stopped on " + selector |
||
717 | |||
718 | return result |
||
719 | } |
||
720 | } |
||
721 | } |
||
722 | }) |
||
723 | |||
724 | jasmine.getEnv().addCustomEqualityTester(function(a, b) { |
||
725 | if (a && b) { |
||
726 | if (a instanceof $ || jasmine.isDomNode(a)) { |
||
727 | var $a = $(a) |
||
728 | |||
729 | if (b instanceof $) |
||
730 | return $a.length == b.length && a.is(b) |
||
731 | |||
732 | return $a.is(b); |
||
733 | } |
||
734 | |||
735 | if (b instanceof $ || jasmine.isDomNode(b)) { |
||
736 | var $b = $(b) |
||
737 | |||
738 | if (a instanceof $) |
||
739 | return a.length == $b.length && $b.is(a) |
||
740 | |||
741 | return $(b).is(a); |
||
742 | } |
||
743 | } |
||
744 | }) |
||
745 | |||
746 | jasmine.getEnv().addCustomEqualityTester(function (a, b) { |
||
747 | if (a instanceof $ && b instanceof $ && a.size() == b.size()) |
||
748 | return a.is(b) |
||
749 | }) |
||
750 | }) |
||
751 | |||
752 | afterEach(function () { |
||
753 | jasmine.getFixtures().cleanUp() |
||
754 | jasmine.getStyleFixtures().cleanUp() |
||
755 | jasmine.jQuery.events.cleanUp() |
||
756 | }) |
||
757 | |||
758 | window.readFixtures = function () { |
||
759 | return jasmine.getFixtures().proxyCallTo_('read', arguments) |
||
760 | } |
||
761 | |||
762 | window.setFixturesPath = jasmine.setFixturesPath; |
||
763 | |||
764 | window.preloadFixtures = function () { |
||
765 | jasmine.getFixtures().proxyCallTo_('preload', arguments) |
||
766 | } |
||
767 | |||
768 | window.loadFixtures = function () { |
||
769 | jasmine.getFixtures().proxyCallTo_('load', arguments) |
||
770 | } |
||
771 | |||
772 | window.appendLoadFixtures = function () { |
||
773 | jasmine.getFixtures().proxyCallTo_('appendLoad', arguments) |
||
774 | } |
||
775 | |||
776 | window.setFixtures = function (html) { |
||
777 | return jasmine.getFixtures().proxyCallTo_('set', arguments) |
||
778 | } |
||
779 | |||
780 | window.appendSetFixtures = function () { |
||
781 | jasmine.getFixtures().proxyCallTo_('appendSet', arguments) |
||
782 | } |
||
783 | |||
784 | window.sandbox = function (attributes) { |
||
785 | return jasmine.getFixtures().sandbox(attributes) |
||
786 | } |
||
787 | |||
788 | window.spyOnEvent = function (selector, eventName) { |
||
789 | return jasmine.jQuery.events.spyOn(selector, eventName) |
||
790 | } |
||
791 | |||
792 | window.preloadStyleFixtures = function () { |
||
793 | jasmine.getStyleFixtures().proxyCallTo_('preload', arguments) |
||
794 | } |
||
795 | |||
796 | window.loadStyleFixtures = function () { |
||
797 | jasmine.getStyleFixtures().proxyCallTo_('load', arguments) |
||
798 | } |
||
799 | |||
800 | window.appendLoadStyleFixtures = function () { |
||
801 | jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments) |
||
802 | } |
||
803 | |||
804 | window.setStyleFixtures = function (html) { |
||
805 | jasmine.getStyleFixtures().proxyCallTo_('set', arguments) |
||
806 | } |
||
807 | |||
808 | window.appendSetStyleFixtures = function (html) { |
||
809 | jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments) |
||
810 | } |
||
811 | |||
812 | window.loadJSONFixtures = function () { |
||
813 | return jasmine.getJSONFixtures().proxyCallTo_('load', arguments) |
||
814 | } |
||
815 | |||
816 | window.getJSONFixture = function (url) { |
||
817 | return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url] |
||
818 | } |
||
819 | }(window, window.jasmine, window.jQuery); |