1 /** 2 * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework. 3 * 4 * @namespace 5 */ 6 var jasmine = {}; 7 8 /** 9 * @private 10 */ 11 jasmine.unimplementedMethod_ = function() { 12 throw new Error("unimplemented method"); 13 }; 14 15 /** 16 * Large or small values here may result in slow test running & "Too much recursion" errors 17 * 18 */ 19 jasmine.UPDATE_INTERVAL = 250; 20 21 /** 22 * Allows for bound functions to be comapred. Internal use only. 23 * 24 * @ignore 25 * @private 26 * @param base {Object} bound 'this' for the function 27 * @param name {Function} function to find 28 */ 29 jasmine.bindOriginal_ = function(base, name) { 30 var original = base[name]; 31 return function() { 32 if (original.apply) { 33 return original.apply(base, arguments); 34 } else { 35 //IE support 36 if (base == window) { 37 return window[name].apply(window, arguments); 38 } 39 } 40 }; 41 }; 42 43 jasmine.setTimeout = jasmine.bindOriginal_(window, 'setTimeout'); 44 jasmine.clearTimeout = jasmine.bindOriginal_(window, 'clearTimeout'); 45 jasmine.setInterval = jasmine.bindOriginal_(window, 'setInterval'); 46 jasmine.clearInterval = jasmine.bindOriginal_(window, 'clearInterval'); 47 48 jasmine.MessageResult = function(text) { 49 this.type = 'MessageResult'; 50 this.text = text; 51 this.trace = new Error(); // todo: test better 52 }; 53 54 jasmine.ExpectationResult = function(params) { 55 this.type = 'ExpectationResult'; 56 this.matcherName = params.matcherName; 57 this.passed_ = params.passed; 58 this.expected = params.expected; 59 this.actual = params.actual; 60 61 /** @deprecated */ 62 this.details = params.details; 63 64 this.message = this.passed_ ? 'Passed.' : params.message; 65 this.trace = this.passed_ ? '' : new Error(this.message); 66 }; 67 68 jasmine.ExpectationResult.prototype.passed = function () { 69 return this.passed_; 70 }; 71 72 /** 73 * Getter for the Jasmine environment. Ensures one gets created 74 */ 75 jasmine.getEnv = function() { 76 return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); 77 }; 78 79 /** 80 * @ignore 81 * @private 82 * @param value 83 * @returns {Boolean} 84 */ 85 jasmine.isArray_ = function(value) { 86 return value && 87 typeof value === 'object' && 88 typeof value.length === 'number' && 89 typeof value.splice === 'function' && 90 !(value.propertyIsEnumerable('length')); 91 }; 92 93 /** 94 * Pretty printer for expecations. Takes any object and turns it into a human-readable string. 95 * 96 * @param value {Object} an object to be outputted 97 * @returns {String} 98 */ 99 jasmine.pp = function(value) { 100 var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); 101 stringPrettyPrinter.format(value); 102 return stringPrettyPrinter.string; 103 }; 104 105 /** 106 * Returns true if the object is a DOM Node. 107 * 108 * @param {Object} obj object to check 109 * @returns {Boolean} 110 */ 111 jasmine.isDomNode = function(obj) { 112 return obj['nodeType'] > 0; 113 }; 114 115 /** 116 * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. 117 * 118 * @example 119 * // don't care about which function is passed in, as long as it's a function 120 * expect(mySpy).wasCalledWith(jasmine.any(Function)); 121 * 122 * @param {Class} clazz 123 * @returns matchable object of the type clazz 124 */ 125 jasmine.any = function(clazz) { 126 return new jasmine.Matchers.Any(clazz); 127 }; 128 129 /** 130 * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. 131 * 132 * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine 133 * expectation syntax. Spies can be checked if they were called or not and what the calling params were. 134 * 135 * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) 136 * Spies are torn down at the end of every spec. 137 * 138 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. 139 * 140 * @example 141 * // a stub 142 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere 143 * 144 * // spy example 145 * var foo = { 146 * not: function(bool) { return !bool; } 147 * } 148 * 149 * // actual foo.not will not be called, execution stops 150 * spyOn(foo, 'not'); 151 152 // foo.not spied upon, execution will continue to implementation 153 * spyOn(foo, 'not').andCallThrough(); 154 * 155 * // fake example 156 * var foo = { 157 * not: function(bool) { return !bool; } 158 * } 159 * 160 * // foo.not(val) will return val 161 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); 162 * 163 * // mock example 164 * foo.not(7 == 7); 165 * expect(foo.not).wasCalled(); 166 * expect(foo.not).wasCalledWith(true); 167 * 168 * @constructor 169 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj 170 * @param {String} name 171 */ 172 jasmine.Spy = function(name) { 173 /** 174 * The name of the spy, if provided. 175 */ 176 this.identity = name || 'unknown'; 177 /** 178 * Is this Object a spy? 179 */ 180 this.isSpy = true; 181 /** 182 * The acutal function this spy stubs. 183 */ 184 this.plan = function() { 185 }; 186 /** 187 * Tracking of the most recent call to the spy. 188 * @example 189 * var mySpy = jasmine.createSpy('foo'); 190 * mySpy(1, 2); 191 * mySpy.mostRecentCall.args = [1, 2]; 192 */ 193 this.mostRecentCall = {}; 194 195 /** 196 * Holds arguments for each call to the spy, indexed by call count 197 * @example 198 * var mySpy = jasmine.createSpy('foo'); 199 * mySpy(1, 2); 200 * mySpy(7, 8); 201 * mySpy.mostRecentCall.args = [7, 8]; 202 * mySpy.argsForCall[0] = [1, 2]; 203 * mySpy.argsForCall[1] = [7, 8]; 204 */ 205 this.argsForCall = []; 206 this.calls = []; 207 }; 208 209 /** 210 * Tells a spy to call through to the actual implemenatation. 211 * 212 * @example 213 * var foo = { 214 * bar: function() { // do some stuff } 215 * } 216 * 217 * // defining a spy on an existing property: foo.bar 218 * spyOn(foo, 'bar').andCallThrough(); 219 */ 220 jasmine.Spy.prototype.andCallThrough = function() { 221 this.plan = this.originalValue; 222 return this; 223 }; 224 225 /** 226 * For setting the return value of a spy. 227 * 228 * @example 229 * // defining a spy from scratch: foo() returns 'baz' 230 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); 231 * 232 * // defining a spy on an existing property: foo.bar() returns 'baz' 233 * spyOn(foo, 'bar').andReturn('baz'); 234 * 235 * @param {Object} value 236 */ 237 jasmine.Spy.prototype.andReturn = function(value) { 238 this.plan = function() { 239 return value; 240 }; 241 return this; 242 }; 243 244 /** 245 * For throwing an exception when a spy is called. 246 * 247 * @example 248 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' 249 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); 250 * 251 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' 252 * spyOn(foo, 'bar').andThrow('baz'); 253 * 254 * @param {String} exceptionMsg 255 */ 256 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { 257 this.plan = function() { 258 throw exceptionMsg; 259 }; 260 return this; 261 }; 262 263 /** 264 * Calls an alternate implementation when a spy is called. 265 * 266 * @example 267 * var baz = function() { 268 * // do some stuff, return something 269 * } 270 * // defining a spy from scratch: foo() calls the function baz 271 * var foo = jasmine.createSpy('spy on foo').andCall(baz); 272 * 273 * // defining a spy on an existing property: foo.bar() calls an anonymnous function 274 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); 275 * 276 * @param {Function} fakeFunc 277 */ 278 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { 279 this.plan = fakeFunc; 280 return this; 281 }; 282 283 /** 284 * Resets all of a spy's the tracking variables so that it can be used again. 285 * 286 * @example 287 * spyOn(foo, 'bar'); 288 * 289 * foo.bar(); 290 * 291 * expect(foo.bar.callCount).toEqual(1); 292 * 293 * foo.bar.reset(); 294 * 295 * expect(foo.bar.callCount).toEqual(0); 296 */ 297 jasmine.Spy.prototype.reset = function() { 298 this.wasCalled = false; 299 this.callCount = 0; 300 this.argsForCall = []; 301 this.calls = []; 302 this.mostRecentCall = {}; 303 }; 304 305 jasmine.createSpy = function(name) { 306 307 var spyObj = function() { 308 spyObj.wasCalled = true; 309 spyObj.callCount++; 310 var args = jasmine.util.argsToArray(arguments); 311 spyObj.mostRecentCall.object = this; 312 spyObj.mostRecentCall.args = args; 313 spyObj.argsForCall.push(args); 314 spyObj.calls.push({object: this, args: args}); 315 return spyObj.plan.apply(this, arguments); 316 }; 317 318 var spy = new jasmine.Spy(name); 319 320 for (var prop in spy) { 321 spyObj[prop] = spy[prop]; 322 } 323 324 spyObj.reset(); 325 326 return spyObj; 327 }; 328 329 /** 330 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something 331 * large in one call. 332 * 333 * @param {String} baseName name of spy class 334 * @param {Array} methodNames array of names of methods to make spies 335 */ 336 jasmine.createSpyObj = function(baseName, methodNames) { 337 var obj = {}; 338 for (var i = 0; i < methodNames.length; i++) { 339 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); 340 } 341 return obj; 342 }; 343 344 jasmine.log = function(message) { 345 jasmine.getEnv().currentSpec.log(message); 346 }; 347 348 /** 349 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. 350 * 351 * @example 352 * // spy example 353 * var foo = { 354 * not: function(bool) { return !bool; } 355 * } 356 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops 357 * 358 * @see jasmine.createSpy 359 * @param obj 360 * @param methodName 361 * @returns a Jasmine spy that can be chained with all spy methods 362 */ 363 var spyOn = function(obj, methodName) { 364 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); 365 }; 366 367 /** 368 * Creates a Jasmine spec that will be added to the current suite. 369 * 370 * // TODO: pending tests 371 * 372 * @example 373 * it('should be true', function() { 374 * expect(true).toEqual(true); 375 * }); 376 * 377 * @param {String} desc description of this specification 378 * @param {Function} func defines the preconditions and expectations of the spec 379 */ 380 var it = function(desc, func) { 381 return jasmine.getEnv().it(desc, func); 382 }; 383 384 /** 385 * Creates a <em>disabled</em> Jasmine spec. 386 * 387 * A convenience method that allows existing specs to be disabled temporarily during development. 388 * 389 * @param {String} desc description of this specification 390 * @param {Function} func defines the preconditions and expectations of the spec 391 */ 392 var xit = function(desc, func) { 393 return jasmine.getEnv().xit(desc, func); 394 }; 395 396 /** 397 * Starts a chain for a Jasmine expectation. 398 * 399 * It is passed an Object that is the actual value and should chain to one of the many 400 * jasmine.Matchers functions. 401 * 402 * @param {Object} actual Actual value to test against and expected value 403 */ 404 var expect = function(actual) { 405 return jasmine.getEnv().currentSpec.expect(actual); 406 }; 407 408 /** 409 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. 410 * 411 * @param {Function} func Function that defines part of a jasmine spec. 412 */ 413 var runs = function(func) { 414 jasmine.getEnv().currentSpec.runs(func); 415 }; 416 417 /** 418 * Waits for a timeout before moving to the next runs()-defined block. 419 * @param {Number} timeout 420 */ 421 var waits = function(timeout) { 422 jasmine.getEnv().currentSpec.waits(timeout); 423 }; 424 425 /** 426 * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. 427 * 428 * @param {Number} timeout 429 * @param {Function} latchFunction 430 * @param {String} message 431 */ 432 var waitsFor = function(timeout, latchFunction, message) { 433 jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); 434 }; 435 436 /** 437 * A function that is called before each spec in a suite. 438 * 439 * Used for spec setup, including validating assumptions. 440 * 441 * @param {Function} beforeEachFunction 442 */ 443 var beforeEach = function(beforeEachFunction) { 444 jasmine.getEnv().beforeEach(beforeEachFunction); 445 }; 446 447 /** 448 * A function that is called after each spec in a suite. 449 * 450 * Used for restoring any state that is hijacked during spec execution. 451 * 452 * @param {Function} afterEachFunction 453 */ 454 var afterEach = function(afterEachFunction) { 455 jasmine.getEnv().afterEach(afterEachFunction); 456 }; 457 458 /** 459 * Defines a suite of specifications. 460 * 461 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared 462 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization 463 * of setup in some tests. 464 * 465 * @example 466 * // TODO: a simple suite 467 * 468 * // TODO: a simple suite with a nested describe block 469 * 470 * @param {String} description A string, usually the class under test. 471 * @param {Function} specDefinitions function that defines several specs. 472 */ 473 var describe = function(description, specDefinitions) { 474 return jasmine.getEnv().describe(description, specDefinitions); 475 }; 476 477 /** 478 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. 479 * 480 * @param {String} description A string, usually the class under test. 481 * @param {Function} specDefinitions function that defines several specs. 482 */ 483 var xdescribe = function(description, specDefinitions) { 484 return jasmine.getEnv().xdescribe(description, specDefinitions); 485 }; 486 487 488 jasmine.XmlHttpRequest = XMLHttpRequest; 489 490 // Provide the XMLHttpRequest class for IE 5.x-6.x: 491 if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { 492 try { 493 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); 494 } catch(e) { 495 } 496 try { 497 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); 498 } catch(e) { 499 } 500 try { 501 return new ActiveXObject("Msxml2.XMLHTTP"); 502 } catch(e) { 503 } 504 try { 505 return new ActiveXObject("Microsoft.XMLHTTP"); 506 } catch(e) { 507 } 508 throw new Error("This browser does not support XMLHttpRequest."); 509 }; 510 511 /** 512 * Adds suite files to an HTML document so that they are executed, thus adding them to the current 513 * Jasmine environment. 514 * 515 * @param {String} url path to the file to include 516 * @param {Boolean} opt_global 517 */ 518 jasmine.include = function(url, opt_global) { 519 if (opt_global) { 520 document.write('<script type="text/javascript" src="' + url + '"></' + 'script>'); 521 } else { 522 var xhr; 523 try { 524 xhr = new jasmine.XmlHttpRequest(); 525 xhr.open("GET", url, false); 526 xhr.send(null); 527 } catch(e) { 528 throw new Error("couldn't fetch " + url + ": " + e); 529 } 530 531 return eval(xhr.responseText); 532 } 533 }; 534 535 jasmine.version_= { 536 "major": 0, 537 "minor": 10, 538 "build": 0, 539 "revision": 1256874141 540 }; 541 /** 542 * @namespace 543 */ 544 jasmine.util = {}; 545 546 /** 547 * Declare that a child class inherite it's prototype from the parent class. 548 * 549 * @private 550 * @param {Function} childClass 551 * @param {Function} parentClass 552 */ 553 jasmine.util.inherit = function(childClass, parentClass) { 554 var subclass = function() { 555 }; 556 subclass.prototype = parentClass.prototype; 557 childClass.prototype = new subclass; 558 }; 559 560 jasmine.util.formatException = function(e) { 561 var lineNumber; 562 if (e.line) { 563 lineNumber = e.line; 564 } 565 else if (e.lineNumber) { 566 lineNumber = e.lineNumber; 567 } 568 569 var file; 570 571 if (e.sourceURL) { 572 file = e.sourceURL; 573 } 574 else if (e.fileName) { 575 file = e.fileName; 576 } 577 578 var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString(); 579 580 if (file && lineNumber) { 581 message += ' in ' + file + ' (line ' + lineNumber + ')'; 582 } 583 584 return message; 585 }; 586 587 jasmine.util.htmlEscape = function(str) { 588 if (!str) return str; 589 return str.replace(/&/g, '&') 590 .replace(/</g, '<') 591 .replace(/>/g, '>'); 592 }; 593 594 jasmine.util.argsToArray = function(args) { 595 var arrayOfArgs = []; 596 for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]); 597 return arrayOfArgs; 598 }; 599 600 jasmine.util.extend = function(destination, source) { 601 for (var property in source) destination[property] = source[property]; 602 return destination; 603 }; 604 605 /** 606 * Environment for Jasmine 607 * 608 * @constructor 609 */ 610 jasmine.Env = function() { 611 this.currentSpec = null; 612 this.currentSuite = null; 613 this.currentRunner_ = new jasmine.Runner(this); 614 615 this.reporter = new jasmine.MultiReporter(); 616 617 this.updateInterval = jasmine.UPDATE_INTERVAL 618 this.lastUpdate = 0; 619 this.specFilter = function() { 620 return true; 621 }; 622 623 this.nextSpecId_ = 0; 624 this.nextSuiteId_ = 0; 625 this.equalityTesters_ = []; 626 }; 627 628 629 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; 630 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; 631 jasmine.Env.prototype.setInterval = jasmine.setInterval; 632 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; 633 634 /** 635 * @returns an object containing jasmine version build info, if set. 636 */ 637 jasmine.Env.prototype.version = function () { 638 if (jasmine.version_) { 639 return jasmine.version_; 640 } else { 641 throw new Error('Version not set'); 642 } 643 }; 644 645 /** 646 * @returns a sequential integer starting at 0 647 */ 648 jasmine.Env.prototype.nextSpecId = function () { 649 return this.nextSpecId_++; 650 }; 651 652 /** 653 * @returns a sequential integer starting at 0 654 */ 655 jasmine.Env.prototype.nextSuiteId = function () { 656 return this.nextSuiteId_++; 657 }; 658 659 /** 660 * Register a reporter to receive status updates from Jasmine. 661 * @param {jasmine.Reporter} reporter An object which will receive status updates. 662 */ 663 jasmine.Env.prototype.addReporter = function(reporter) { 664 this.reporter.addReporter(reporter); 665 }; 666 667 jasmine.Env.prototype.execute = function() { 668 this.currentRunner_.execute(); 669 }; 670 671 jasmine.Env.prototype.describe = function(description, specDefinitions) { 672 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); 673 674 var parentSuite = this.currentSuite; 675 if (parentSuite) { 676 parentSuite.add(suite); 677 } else { 678 this.currentRunner_.add(suite); 679 } 680 681 this.currentSuite = suite; 682 683 specDefinitions.call(suite); 684 685 this.currentSuite = parentSuite; 686 687 return suite; 688 }; 689 690 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { 691 if (this.currentSuite) { 692 this.currentSuite.beforeEach(beforeEachFunction); 693 } else { 694 this.currentRunner_.beforeEach(beforeEachFunction); 695 } 696 }; 697 698 jasmine.Env.prototype.currentRunner = function () { 699 return this.currentRunner_; 700 }; 701 702 jasmine.Env.prototype.afterEach = function(afterEachFunction) { 703 if (this.currentSuite) { 704 this.currentSuite.afterEach(afterEachFunction); 705 } else { 706 this.currentRunner_.afterEach(afterEachFunction); 707 } 708 709 }; 710 711 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { 712 return { 713 execute: function() { 714 } 715 }; 716 }; 717 718 jasmine.Env.prototype.it = function(description, func) { 719 var spec = new jasmine.Spec(this, this.currentSuite, description); 720 this.currentSuite.add(spec); 721 this.currentSpec = spec; 722 723 if (func) { 724 spec.runs(func); 725 } 726 727 return spec; 728 }; 729 730 jasmine.Env.prototype.xit = function(desc, func) { 731 return { 732 id: this.nextSpecId(), 733 runs: function() { 734 } 735 }; 736 }; 737 738 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { 739 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { 740 return true; 741 } 742 743 a.__Jasmine_been_here_before__ = b; 744 b.__Jasmine_been_here_before__ = a; 745 746 var hasKey = function(obj, keyName) { 747 return obj != null && obj[keyName] !== undefined; 748 }; 749 750 for (var property in b) { 751 if (!hasKey(a, property) && hasKey(b, property)) { 752 mismatchKeys.push("expected has key '" + property + "', but missing from actual."); 753 } 754 } 755 for (property in a) { 756 if (!hasKey(b, property) && hasKey(a, property)) { 757 mismatchKeys.push("expected missing key '" + property + "', but present in actual."); 758 } 759 } 760 for (property in b) { 761 if (property == '__Jasmine_been_here_before__') continue; 762 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { 763 mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); 764 } 765 } 766 767 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { 768 mismatchValues.push("arrays were not the same length"); 769 } 770 771 delete a.__Jasmine_been_here_before__; 772 delete b.__Jasmine_been_here_before__; 773 return (mismatchKeys.length == 0 && mismatchValues.length == 0); 774 }; 775 776 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { 777 mismatchKeys = mismatchKeys || []; 778 mismatchValues = mismatchValues || []; 779 780 if (a === b) return true; 781 782 if (a === undefined || a === null || b === undefined || b === null) { 783 return (a == undefined && b == undefined); 784 } 785 786 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { 787 return a === b; 788 } 789 790 if (a instanceof Date && b instanceof Date) { 791 return a.getTime() == b.getTime(); 792 } 793 794 if (a instanceof jasmine.Matchers.Any) { 795 return a.matches(b); 796 } 797 798 if (b instanceof jasmine.Matchers.Any) { 799 return b.matches(a); 800 } 801 802 if (typeof a === "object" && typeof b === "object") { 803 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); 804 } 805 806 for (var i = 0; i < this.equalityTesters_.length; i++) { 807 var equalityTester = this.equalityTesters_[i]; 808 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); 809 if (result !== undefined) return result; 810 } 811 812 //Straight check 813 return (a === b); 814 }; 815 816 jasmine.Env.prototype.contains_ = function(haystack, needle) { 817 if (jasmine.isArray_(haystack)) { 818 for (var i = 0; i < haystack.length; i++) { 819 if (this.equals_(haystack[i], needle)) return true; 820 } 821 return false; 822 } 823 return haystack.indexOf(needle) >= 0; 824 }; 825 826 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { 827 this.equalityTesters_.push(equalityTester); 828 }; 829 /** No-op base class for Jasmine reporters. 830 * 831 * @constructor 832 */ 833 jasmine.Reporter = function() { 834 }; 835 836 //noinspection JSUnusedLocalSymbols 837 jasmine.Reporter.prototype.reportRunnerStarting = function(runner) { 838 }; 839 840 //noinspection JSUnusedLocalSymbols 841 jasmine.Reporter.prototype.reportRunnerResults = function(runner) { 842 }; 843 844 //noinspection JSUnusedLocalSymbols 845 jasmine.Reporter.prototype.reportSuiteResults = function(suite) { 846 }; 847 848 //noinspection JSUnusedLocalSymbols 849 jasmine.Reporter.prototype.reportSpecResults = function(spec) { 850 }; 851 852 //noinspection JSUnusedLocalSymbols 853 jasmine.Reporter.prototype.log = function(str) { 854 }; 855 856 /** 857 * Blocks are functions with executable code that make up a spec. 858 * 859 * @constructor 860 * @param {jasmine.Env} env 861 * @param {Function} func 862 * @param {jasmine.Spec} spec 863 */ 864 jasmine.Block = function(env, func, spec) { 865 this.env = env; 866 this.func = func; 867 this.spec = spec; 868 }; 869 870 jasmine.Block.prototype.execute = function(onComplete) { 871 try { 872 this.func.apply(this.spec); 873 } catch (e) { 874 this.spec.fail(e); 875 } 876 onComplete(); 877 }; 878 /** JavaScript API reporter. 879 * 880 * @constructor 881 */ 882 jasmine.JsApiReporter = function() { 883 this.started = false; 884 this.finished = false; 885 this.suites_ = []; 886 this.results_ = {}; 887 }; 888 889 jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { 890 this.started = true; 891 var suites = runner.suites(); 892 for (var i = 0; i < suites.length; i++) { 893 var suite = suites[i]; 894 this.suites_.push(this.summarize_(suite)); 895 } 896 }; 897 898 jasmine.JsApiReporter.prototype.suites = function() { 899 return this.suites_; 900 }; 901 902 jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { 903 var isSuite = suiteOrSpec instanceof jasmine.Suite 904 var summary = { 905 id: suiteOrSpec.id, 906 name: suiteOrSpec.description, 907 type: isSuite ? 'suite' : 'spec', 908 children: [] 909 }; 910 if (isSuite) { 911 var specs = suiteOrSpec.specs(); 912 for (var i = 0; i < specs.length; i++) { 913 summary.children.push(this.summarize_(specs[i])); 914 } 915 } 916 return summary; 917 }; 918 919 jasmine.JsApiReporter.prototype.results = function() { 920 return this.results_; 921 }; 922 923 jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { 924 return this.results_[specId]; 925 }; 926 927 //noinspection JSUnusedLocalSymbols 928 jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { 929 this.finished = true; 930 }; 931 932 //noinspection JSUnusedLocalSymbols 933 jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { 934 }; 935 936 //noinspection JSUnusedLocalSymbols 937 jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { 938 this.results_[spec.id] = { 939 messages: spec.results().getItems(), 940 result: spec.results().failedCount > 0 ? "failed" : "passed" 941 }; 942 }; 943 944 //noinspection JSUnusedLocalSymbols 945 jasmine.JsApiReporter.prototype.log = function(str) { 946 }; 947 948 jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){ 949 var results = {}; 950 for (var i = 0; i < specIds.length; i++) { 951 var specId = specIds[i]; 952 results[specId] = this.summarizeResult_(this.results_[specId]); 953 } 954 return results; 955 }; 956 957 jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ 958 var summaryMessages = []; 959 for (var messageIndex in result.messages) { 960 var resultMessage = result.messages[messageIndex]; 961 summaryMessages.push({ 962 text: resultMessage.text, 963 passed: resultMessage.passed ? resultMessage.passed() : true, 964 type: resultMessage.type, 965 message: resultMessage.message, 966 trace: { 967 stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : undefined 968 } 969 }); 970 }; 971 972 var summaryResult = { 973 result : result.result, 974 messages : summaryMessages 975 }; 976 977 return summaryResult; 978 }; 979 980 /** 981 * @constructor 982 * @param {jasmine.Env} env 983 * @param actual 984 * @param {jasmine.NestedResults} results 985 */ 986 jasmine.Matchers = function(env, actual, spec) { 987 this.env = env; 988 this.actual = actual; 989 this.spec = spec; 990 }; 991 992 jasmine.Matchers.pp = function(str) { 993 return jasmine.util.htmlEscape(jasmine.pp(str)); 994 }; 995 996 jasmine.Matchers.prototype.report = function(result, failing_message, details) { 997 var expectationResult = new jasmine.ExpectationResult({ 998 passed: result, 999 message: failing_message, 1000 details: details 1001 }); 1002 this.spec.addMatcherResult(expectationResult); 1003 return result; 1004 }; 1005 1006 jasmine.Matchers.addMatcher = function(matcherName, options) { 1007 jasmine.Matchers.prototype[matcherName] = function () { 1008 jasmine.util.extend(this, options); 1009 var matcherArgs = jasmine.util.argsToArray(arguments); 1010 var args = [this.actual].concat(matcherArgs); 1011 var result = options.test.apply(this, args); 1012 var message; 1013 if (!result) { 1014 message = options.message.apply(this, args); 1015 } 1016 var expectationResult = new jasmine.ExpectationResult({ 1017 matcherName: matcherName, 1018 passed: result, 1019 expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], 1020 actual: this.actual, 1021 message: message 1022 }); 1023 this.spec.addMatcherResult(expectationResult); 1024 return result; 1025 }; 1026 }; 1027 1028 1029 /** 1030 * toBe: compares the actual to the expected using === 1031 * @param expected 1032 */ 1033 1034 jasmine.Matchers.addMatcher('toBe', { 1035 test: function (actual, expected) { 1036 return actual === expected; 1037 }, 1038 message: function(actual, expected) { 1039 return "Expected " + jasmine.pp(actual) + " to be " + jasmine.pp(expected); 1040 } 1041 }); 1042 1043 /** 1044 * toNotBe: compares the actual to the expected using !== 1045 * @param expected 1046 */ 1047 jasmine.Matchers.addMatcher('toNotBe', { 1048 test: function (actual, expected) { 1049 return actual !== expected; 1050 }, 1051 message: function(actual, expected) { 1052 return "Expected " + jasmine.pp(actual) + " to not be " + jasmine.pp(expected); 1053 } 1054 }); 1055 1056 /** 1057 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. 1058 * 1059 * @param expected 1060 */ 1061 1062 jasmine.Matchers.addMatcher('toEqual', { 1063 test: function (actual, expected) { 1064 return this.env.equals_(actual, expected); 1065 }, 1066 message: function(actual, expected) { 1067 return "Expected " + jasmine.pp(actual) + " to equal " + jasmine.pp(expected); 1068 } 1069 }); 1070 1071 /** 1072 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual 1073 * @param expected 1074 */ 1075 jasmine.Matchers.addMatcher('toNotEqual', { 1076 test: function (actual, expected) { 1077 return !this.env.equals_(actual, expected); 1078 }, 1079 message: function(actual, expected) { 1080 return "Expected " + jasmine.pp(actual) + " to not equal " + jasmine.pp(expected); 1081 } 1082 }); 1083 1084 /** 1085 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes 1086 * a pattern or a String. 1087 * 1088 * @param reg_exp 1089 */ 1090 jasmine.Matchers.addMatcher('toMatch', { 1091 test: function(actual, expected) { 1092 return new RegExp(expected).test(actual); 1093 }, 1094 message: function(actual, expected) { 1095 return jasmine.pp(actual) + " does not match the regular expression " + new RegExp(expected).toString(); 1096 } 1097 }); 1098 1099 /** 1100 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch 1101 * @param reg_exp 1102 */ 1103 1104 jasmine.Matchers.addMatcher('toNotMatch', { 1105 test: function(actual, expected) { 1106 return !(new RegExp(expected).test(actual)); 1107 }, 1108 message: function(actual, expected) { 1109 return jasmine.pp(actual) + " should not match " + new RegExp(expected).toString(); 1110 } 1111 }); 1112 1113 /** 1114 * Matcher that compares the acutal to undefined. 1115 */ 1116 1117 jasmine.Matchers.addMatcher('toBeDefined', { 1118 test: function(actual) { 1119 return (actual !== undefined); 1120 }, 1121 message: function() { 1122 return 'Expected actual to not be undefined.'; 1123 } 1124 }); 1125 1126 /** 1127 * Matcher that compares the acutal to undefined. 1128 */ 1129 1130 jasmine.Matchers.addMatcher('toBeUndefined', { 1131 test: function(actual) { 1132 return (actual === undefined); 1133 }, 1134 message: function(actual) { 1135 return 'Expected ' + jasmine.pp(actual) + ' to be undefined.'; 1136 } 1137 }); 1138 1139 /** 1140 * Matcher that compares the actual to null. 1141 * 1142 */ 1143 jasmine.Matchers.addMatcher('toBeNull', { 1144 test: function(actual) { 1145 return (actual === null); 1146 }, 1147 message: function(actual) { 1148 return 'Expected ' + jasmine.pp(actual) + ' to be null.'; 1149 } 1150 }); 1151 1152 /** 1153 * Matcher that boolean not-nots the actual. 1154 */ 1155 jasmine.Matchers.addMatcher('toBeTruthy', { 1156 test: function(actual) { 1157 return !!actual; 1158 }, 1159 message: function() { 1160 return 'Expected actual to be truthy'; 1161 } 1162 }); 1163 1164 1165 /** 1166 * Matcher that boolean nots the actual. 1167 */ 1168 jasmine.Matchers.addMatcher('toBeFalsy', { 1169 test: function(actual) { 1170 return !actual; 1171 }, 1172 message: function(actual) { 1173 return 'Expected ' + jasmine.pp(actual) + ' to be falsy'; 1174 } 1175 }); 1176 1177 /** 1178 * Matcher that checks to see if the acutal, a Jasmine spy, was called. 1179 */ 1180 1181 jasmine.Matchers.addMatcher('wasCalled', { 1182 getActual_: function() { 1183 var args = jasmine.util.argsToArray(arguments); 1184 if (args.length > 1) { 1185 throw(new Error('wasCalled does not take arguments, use wasCalledWith')); 1186 } 1187 return args.splice(0, 1)[0]; 1188 }, 1189 test: function() { 1190 var actual = this.getActual_.apply(this, arguments); 1191 if (!actual || !actual.isSpy) { 1192 return false; 1193 } 1194 return actual.wasCalled; 1195 }, 1196 message: function() { 1197 var actual = this.getActual_.apply(this, arguments); 1198 if (!actual || !actual.isSpy) { 1199 return 'Actual is not a spy.'; 1200 } 1201 return "Expected spy " + actual.identity + " to have been called."; 1202 } 1203 }); 1204 1205 /** 1206 * Matcher that checks to see if the acutal, a Jasmine spy, was not called. 1207 */ 1208 jasmine.Matchers.addMatcher('wasNotCalled', { 1209 getActual_: function() { 1210 var args = jasmine.util.argsToArray(arguments); 1211 return args.splice(0, 1)[0]; 1212 }, 1213 test: function() { 1214 var actual = this.getActual_.apply(this, arguments); 1215 if (!actual || !actual.isSpy) { 1216 return false; 1217 } 1218 return !actual.wasCalled; 1219 }, 1220 message: function() { 1221 var actual = this.getActual_.apply(this, arguments); 1222 if (!actual || !actual.isSpy) { 1223 return 'Actual is not a spy.'; 1224 } 1225 return "Expected spy " + actual.identity + " to not have been called."; 1226 } 1227 }); 1228 1229 jasmine.Matchers.addMatcher('wasCalledWith', { 1230 test: function() { 1231 var args = jasmine.util.argsToArray(arguments); 1232 var actual = args.splice(0, 1)[0]; 1233 if (!actual || !actual.isSpy) { 1234 return false; 1235 } 1236 return this.env.contains_(actual.argsForCall, args); 1237 }, 1238 message: function() { 1239 var args = jasmine.util.argsToArray(arguments); 1240 var actual = args.splice(0, 1)[0]; 1241 var message; 1242 if (!actual || !actual.isSpy) { 1243 message = 'Actual is not a spy'; 1244 } else { 1245 message = "Expected spy to have been called with " + jasmine.pp(args) + " but was called with " + actual.argsForCall; 1246 } 1247 return message; 1248 } 1249 }); 1250 1251 /** 1252 * Matcher that checks to see if the acutal, a Jasmine spy, was called with a set of parameters. 1253 * 1254 * @example 1255 * 1256 */ 1257 1258 /** 1259 * Matcher that checks that the expected item is an element in the actual Array. 1260 * 1261 * @param {Object} item 1262 */ 1263 1264 jasmine.Matchers.addMatcher('toContain', { 1265 test: function(actual, expected) { 1266 return this.env.contains_(actual, expected); 1267 }, 1268 message: function(actual, expected) { 1269 return 'Expected ' + jasmine.pp(actual) + ' to contain ' + jasmine.pp(expected); 1270 } 1271 }); 1272 1273 /** 1274 * Matcher that checks that the expected item is NOT an element in the actual Array. 1275 * 1276 * @param {Object} item 1277 */ 1278 jasmine.Matchers.addMatcher('toNotContain', { 1279 test: function(actual, expected) { 1280 return !this.env.contains_(actual, expected); 1281 }, 1282 message: function(actual, expected) { 1283 return 'Expected ' + jasmine.pp(actual) + ' to not contain ' + jasmine.pp(expected); 1284 } 1285 }); 1286 1287 jasmine.Matchers.addMatcher('toBeLessThan', { 1288 test: function(actual, expected) { 1289 return actual < expected; 1290 }, 1291 message: function(actual, expected) { 1292 return 'Expected ' + jasmine.pp(actual) + ' to be less than ' + jasmine.pp(expected); 1293 } 1294 }); 1295 1296 jasmine.Matchers.addMatcher('toBeGreaterThan', { 1297 test: function(actual, expected) { 1298 return actual > expected; 1299 }, 1300 message: function(actual, expected) { 1301 return 'Expected ' + jasmine.pp(actual) + ' to be greater than ' + jasmine.pp(expected); 1302 } 1303 }); 1304 1305 /** 1306 * Matcher that checks that the expected exception was thrown by the actual. 1307 * 1308 * @param {String} expectedException 1309 */ 1310 jasmine.Matchers.addMatcher('toThrow', { 1311 getException_: function(actual, expected) { 1312 var exception; 1313 if (typeof actual != 'function') { 1314 throw new Error('Actual is not a function'); 1315 } 1316 try { 1317 actual(); 1318 } catch (e) { 1319 exception = e; 1320 } 1321 return exception; 1322 }, 1323 test: function(actual, expected) { 1324 var result = false; 1325 var exception = this.getException_(actual, expected); 1326 if (exception) { 1327 result = (expected === undefined || this.env.equals_(exception.message || exception, expected.message || expected)); 1328 } 1329 return result; 1330 }, 1331 message: function(actual, expected) { 1332 var exception = this.getException_(actual, expected); 1333 if (exception && (expected === undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { 1334 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' '); 1335 } else { 1336 return "Expected function to throw an exception."; 1337 } 1338 } 1339 }); 1340 1341 jasmine.Matchers.Any = function(expectedClass) { 1342 this.expectedClass = expectedClass; 1343 }; 1344 1345 jasmine.Matchers.Any.prototype.matches = function(other) { 1346 if (this.expectedClass == String) { 1347 return typeof other == 'string' || other instanceof String; 1348 } 1349 1350 if (this.expectedClass == Number) { 1351 return typeof other == 'number' || other instanceof Number; 1352 } 1353 1354 if (this.expectedClass == Function) { 1355 return typeof other == 'function' || other instanceof Function; 1356 } 1357 1358 if (this.expectedClass == Object) { 1359 return typeof other == 'object'; 1360 } 1361 1362 return other instanceof this.expectedClass; 1363 }; 1364 1365 jasmine.Matchers.Any.prototype.toString = function() { 1366 return '<jasmine.any(' + this.expectedClass + ')>'; 1367 }; 1368 1369 /** 1370 * @constructor 1371 */ 1372 jasmine.MultiReporter = function() { 1373 this.subReporters_ = []; 1374 }; 1375 jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); 1376 1377 jasmine.MultiReporter.prototype.addReporter = function(reporter) { 1378 this.subReporters_.push(reporter); 1379 }; 1380 1381 (function() { 1382 var functionNames = ["reportRunnerStarting", "reportRunnerResults", "reportSuiteResults", "reportSpecResults", "log"]; 1383 for (var i = 0; i < functionNames.length; i++) { 1384 var functionName = functionNames[i]; 1385 jasmine.MultiReporter.prototype[functionName] = (function(functionName) { 1386 return function() { 1387 for (var j = 0; j < this.subReporters_.length; j++) { 1388 var subReporter = this.subReporters_[j]; 1389 if (subReporter[functionName]) { 1390 subReporter[functionName].apply(subReporter, arguments); 1391 } 1392 } 1393 }; 1394 })(functionName); 1395 } 1396 })(); 1397 /** 1398 * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults 1399 * 1400 * @constructor 1401 */ 1402 jasmine.NestedResults = function() { 1403 /** 1404 * The total count of results 1405 */ 1406 this.totalCount = 0; 1407 /** 1408 * Number of passed results 1409 */ 1410 this.passedCount = 0; 1411 /** 1412 * Number of failed results 1413 */ 1414 this.failedCount = 0; 1415 /** 1416 * Was this suite/spec skipped? 1417 */ 1418 this.skipped = false; 1419 /** 1420 * @ignore 1421 */ 1422 this.items_ = []; 1423 }; 1424 1425 /** 1426 * Roll up the result counts. 1427 * 1428 * @param result 1429 */ 1430 jasmine.NestedResults.prototype.rollupCounts = function(result) { 1431 this.totalCount += result.totalCount; 1432 this.passedCount += result.passedCount; 1433 this.failedCount += result.failedCount; 1434 }; 1435 1436 /** 1437 * Tracks a result's message. 1438 * @param message 1439 */ 1440 jasmine.NestedResults.prototype.log = function(message) { 1441 this.items_.push(new jasmine.MessageResult(message)); 1442 }; 1443 1444 /** 1445 * Getter for the results: message & results. 1446 */ 1447 jasmine.NestedResults.prototype.getItems = function() { 1448 return this.items_; 1449 }; 1450 1451 /** 1452 * Adds a result, tracking counts (total, passed, & failed) 1453 * @param {jasmine.ExpectationResult|jasmine.NestedResults} result 1454 */ 1455 jasmine.NestedResults.prototype.addResult = function(result) { 1456 if (result.type != 'MessageResult') { 1457 if (result.items_) { 1458 this.rollupCounts(result); 1459 } else { 1460 this.totalCount++; 1461 if (result.passed()) { 1462 this.passedCount++; 1463 } else { 1464 this.failedCount++; 1465 } 1466 } 1467 } 1468 this.items_.push(result); 1469 }; 1470 1471 /** 1472 * @returns {Boolean} True if <b>everything</b> below passed 1473 */ 1474 jasmine.NestedResults.prototype.passed = function() { 1475 return this.passedCount === this.totalCount; 1476 }; 1477 /** 1478 * Base class for pretty printing for expectation results. 1479 */ 1480 jasmine.PrettyPrinter = function() { 1481 this.ppNestLevel_ = 0; 1482 }; 1483 1484 /** 1485 * Formats a value in a nice, human-readable string. 1486 * 1487 * @param value 1488 * @returns {String} 1489 */ 1490 jasmine.PrettyPrinter.prototype.format = function(value) { 1491 if (this.ppNestLevel_ > 40) { 1492 // return '(jasmine.pp nested too deeply!)'; 1493 throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); 1494 } 1495 1496 this.ppNestLevel_++; 1497 try { 1498 if (value === undefined) { 1499 this.emitScalar('undefined'); 1500 } else if (value === null) { 1501 this.emitScalar('null'); 1502 } else if (value.navigator && value.frames && value.setTimeout) { 1503 this.emitScalar('<window>'); 1504 } else if (value instanceof jasmine.Matchers.Any) { 1505 this.emitScalar(value.toString()); 1506 } else if (typeof value === 'string') { 1507 this.emitString(value); 1508 } else if (typeof value === 'function') { 1509 this.emitScalar('Function'); 1510 } else if (typeof value.nodeType === 'number') { 1511 this.emitScalar('HTMLNode'); 1512 } else if (value instanceof Date) { 1513 this.emitScalar('Date(' + value + ')'); 1514 } else if (value.__Jasmine_been_here_before__) { 1515 this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); 1516 } else if (jasmine.isArray_(value) || typeof value == 'object') { 1517 value.__Jasmine_been_here_before__ = true; 1518 if (jasmine.isArray_(value)) { 1519 this.emitArray(value); 1520 } else { 1521 this.emitObject(value); 1522 } 1523 delete value.__Jasmine_been_here_before__; 1524 } else { 1525 this.emitScalar(value.toString()); 1526 } 1527 } finally { 1528 this.ppNestLevel_--; 1529 } 1530 }; 1531 1532 jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { 1533 for (var property in obj) { 1534 if (property == '__Jasmine_been_here_before__') continue; 1535 fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false); 1536 } 1537 }; 1538 1539 jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; 1540 jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; 1541 jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; 1542 jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; 1543 1544 jasmine.StringPrettyPrinter = function() { 1545 jasmine.PrettyPrinter.call(this); 1546 1547 this.string = ''; 1548 }; 1549 jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); 1550 1551 jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { 1552 this.append(value); 1553 }; 1554 1555 jasmine.StringPrettyPrinter.prototype.emitString = function(value) { 1556 this.append("'" + value + "'"); 1557 }; 1558 1559 jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { 1560 this.append('[ '); 1561 for (var i = 0; i < array.length; i++) { 1562 if (i > 0) { 1563 this.append(', '); 1564 } 1565 this.format(array[i]); 1566 } 1567 this.append(' ]'); 1568 }; 1569 1570 jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { 1571 var self = this; 1572 this.append('{ '); 1573 var first = true; 1574 1575 this.iterateObject(obj, function(property, isGetter) { 1576 if (first) { 1577 first = false; 1578 } else { 1579 self.append(', '); 1580 } 1581 1582 self.append(property); 1583 self.append(' : '); 1584 if (isGetter) { 1585 self.append('<getter>'); 1586 } else { 1587 self.format(obj[property]); 1588 } 1589 }); 1590 1591 this.append(' }'); 1592 }; 1593 1594 jasmine.StringPrettyPrinter.prototype.append = function(value) { 1595 this.string += value; 1596 }; 1597 jasmine.Queue = function(env) { 1598 this.env = env; 1599 this.blocks = []; 1600 this.running = false; 1601 this.index = 0; 1602 this.offset = 0; 1603 }; 1604 1605 jasmine.Queue.prototype.addBefore = function(block) { 1606 this.blocks.unshift(block); 1607 }; 1608 1609 jasmine.Queue.prototype.add = function(block) { 1610 this.blocks.push(block); 1611 }; 1612 1613 jasmine.Queue.prototype.insertNext = function(block) { 1614 this.blocks.splice((this.index + this.offset + 1), 0, block); 1615 this.offset++; 1616 }; 1617 1618 jasmine.Queue.prototype.start = function(onComplete) { 1619 this.running = true; 1620 this.onComplete = onComplete; 1621 this.next_(); 1622 }; 1623 1624 jasmine.Queue.prototype.isRunning = function() { 1625 return this.running; 1626 }; 1627 1628 jasmine.Queue.LOOP_DONT_RECURSE = true; 1629 1630 jasmine.Queue.prototype.next_ = function() { 1631 var self = this; 1632 var goAgain = true; 1633 1634 while (goAgain) { 1635 goAgain = false; 1636 1637 if (self.index < self.blocks.length) { 1638 var calledSynchronously = true; 1639 var completedSynchronously = false; 1640 1641 var onComplete = function () { 1642 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { 1643 completedSynchronously = true; 1644 return; 1645 } 1646 1647 self.offset = 0; 1648 self.index++; 1649 1650 var now = new Date().getTime(); 1651 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { 1652 self.env.lastUpdate = now; 1653 self.env.setTimeout(function() { 1654 self.next_(); 1655 }, 0); 1656 } else { 1657 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { 1658 goAgain = true; 1659 } else { 1660 self.next_(); 1661 } 1662 } 1663 }; 1664 self.blocks[self.index].execute(onComplete); 1665 1666 calledSynchronously = false; 1667 if (completedSynchronously) { 1668 onComplete(); 1669 } 1670 1671 } else { 1672 self.running = false; 1673 if (self.onComplete) { 1674 self.onComplete(); 1675 } 1676 } 1677 } 1678 }; 1679 1680 jasmine.Queue.prototype.results = function() { 1681 var results = new jasmine.NestedResults(); 1682 for (var i = 0; i < this.blocks.length; i++) { 1683 if (this.blocks[i].results) { 1684 results.addResult(this.blocks[i].results()); 1685 } 1686 } 1687 return results; 1688 }; 1689 1690 1691 /* JasmineReporters.reporter 1692 * Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to 1693 * descendants of this object to do something with the results (see json_reporter.js) 1694 */ 1695 jasmine.Reporters = {}; 1696 1697 jasmine.Reporters.reporter = function(callbacks) { 1698 var that = { 1699 callbacks: callbacks || {}, 1700 1701 doCallback: function(callback, results) { 1702 if (callback) { 1703 callback(results); 1704 } 1705 }, 1706 1707 reportRunnerResults: function(runner) { 1708 that.doCallback(that.callbacks.runnerCallback, runner); 1709 }, 1710 reportSuiteResults: function(suite) { 1711 that.doCallback(that.callbacks.suiteCallback, suite); 1712 }, 1713 reportSpecResults: function(spec) { 1714 that.doCallback(that.callbacks.specCallback, spec); 1715 }, 1716 log: function (str) { 1717 if (console && console.log) console.log(str); 1718 } 1719 }; 1720 1721 return that; 1722 }; 1723 1724 /** 1725 * Runner 1726 * 1727 * @constructor 1728 * @param {jasmine.Env} env 1729 */ 1730 jasmine.Runner = function(env) { 1731 var self = this; 1732 self.env = env; 1733 self.queue = new jasmine.Queue(env); 1734 self.before_ = []; 1735 self.after_ = []; 1736 self.suites_ = []; 1737 }; 1738 1739 jasmine.Runner.prototype.execute = function() { 1740 var self = this; 1741 if (self.env.reporter.reportRunnerStarting) { 1742 self.env.reporter.reportRunnerStarting(this); 1743 } 1744 self.queue.start(function () { 1745 self.finishCallback(); 1746 }); 1747 }; 1748 1749 jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { 1750 beforeEachFunction.typeName = 'beforeEach'; 1751 this.before_.push(beforeEachFunction); 1752 }; 1753 1754 jasmine.Runner.prototype.afterEach = function(afterEachFunction) { 1755 afterEachFunction.typeName = 'afterEach'; 1756 this.after_.push(afterEachFunction); 1757 }; 1758 1759 1760 jasmine.Runner.prototype.finishCallback = function() { 1761 this.env.reporter.reportRunnerResults(this); 1762 }; 1763 1764 jasmine.Runner.prototype.addSuite = function(suite) { 1765 this.suites_.push(suite); 1766 }; 1767 1768 jasmine.Runner.prototype.add = function(block) { 1769 if (block instanceof jasmine.Suite) { 1770 this.addSuite(block); 1771 } 1772 this.queue.add(block); 1773 }; 1774 1775 jasmine.Runner.prototype.specs = function () { 1776 var suites = this.suites(); 1777 var specs = []; 1778 for (var i = 0; i < suites.length; i++) { 1779 specs = specs.concat(suites[i].specs()); 1780 } 1781 return specs; 1782 }; 1783 1784 1785 jasmine.Runner.prototype.suites = function() { 1786 return this.suites_; 1787 }; 1788 1789 jasmine.Runner.prototype.results = function() { 1790 return this.queue.results(); 1791 }; 1792 /** 1793 * Internal representation of a Jasmine specification, or test. 1794 * 1795 * @constructor 1796 * @param {jasmine.Env} env 1797 * @param {jasmine.Suite} suite 1798 * @param {String} description 1799 */ 1800 jasmine.Spec = function(env, suite, description) { 1801 if (!env) { 1802 throw new Error('jasmine.Env() required'); 1803 } 1804 ; 1805 if (!suite) { 1806 throw new Error('jasmine.Suite() required'); 1807 } 1808 ; 1809 var spec = this; 1810 spec.id = env.nextSpecId ? env.nextSpecId() : null; 1811 spec.env = env; 1812 spec.suite = suite; 1813 spec.description = description; 1814 spec.queue = new jasmine.Queue(env); 1815 1816 spec.afterCallbacks = []; 1817 spec.spies_ = []; 1818 1819 spec.results_ = new jasmine.NestedResults(); 1820 spec.results_.description = description; 1821 spec.matchersClass = null; 1822 }; 1823 1824 jasmine.Spec.prototype.getFullName = function() { 1825 return this.suite.getFullName() + ' ' + this.description + '.'; 1826 }; 1827 1828 1829 jasmine.Spec.prototype.results = function() { 1830 return this.results_; 1831 }; 1832 1833 jasmine.Spec.prototype.log = function(message) { 1834 return this.results_.log(message); 1835 }; 1836 1837 jasmine.Spec.prototype.runs = function (func) { 1838 var block = new jasmine.Block(this.env, func, this); 1839 this.addToQueue(block); 1840 return this; 1841 }; 1842 1843 jasmine.Spec.prototype.addToQueue = function (block) { 1844 if (this.queue.isRunning()) { 1845 this.queue.insertNext(block); 1846 } else { 1847 this.queue.add(block); 1848 } 1849 }; 1850 1851 jasmine.Spec.prototype.addMatcherResult = function(result) { 1852 this.results_.addResult(result); 1853 }; 1854 1855 jasmine.Spec.prototype.expect = function(actual) { 1856 return new (this.getMatchersClass_())(this.env, actual, this); 1857 }; 1858 1859 jasmine.Spec.prototype.waits = function(timeout) { 1860 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); 1861 this.addToQueue(waitsFunc); 1862 return this; 1863 }; 1864 1865 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { 1866 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); 1867 this.addToQueue(waitsForFunc); 1868 return this; 1869 }; 1870 1871 jasmine.Spec.prototype.fail = function (e) { 1872 var expectationResult = new jasmine.ExpectationResult({ 1873 passed: false, 1874 message: e ? jasmine.util.formatException(e) : 'Exception' 1875 }); 1876 this.results_.addResult(expectationResult); 1877 }; 1878 1879 jasmine.Spec.prototype.getMatchersClass_ = function() { 1880 return this.matchersClass || jasmine.Matchers; 1881 }; 1882 1883 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { 1884 var parent = this.getMatchersClass_(); 1885 var newMatchersClass = function() { 1886 parent.apply(this, arguments); 1887 }; 1888 jasmine.util.inherit(newMatchersClass, parent); 1889 for (var method in matchersPrototype) { 1890 newMatchersClass.prototype[method] = matchersPrototype[method]; 1891 } 1892 this.matchersClass = newMatchersClass; 1893 }; 1894 1895 jasmine.Spec.prototype.finishCallback = function() { 1896 this.env.reporter.reportSpecResults(this); 1897 }; 1898 1899 jasmine.Spec.prototype.finish = function(onComplete) { 1900 this.removeAllSpies(); 1901 this.finishCallback(); 1902 if (onComplete) { 1903 onComplete(); 1904 } 1905 }; 1906 1907 jasmine.Spec.prototype.after = function(doAfter, test) { 1908 1909 if (this.queue.isRunning()) { 1910 this.queue.add(new jasmine.Block(this.env, doAfter, this)); 1911 } else { 1912 this.afterCallbacks.unshift(doAfter); 1913 } 1914 }; 1915 1916 jasmine.Spec.prototype.execute = function(onComplete) { 1917 var spec = this; 1918 if (!spec.env.specFilter(spec)) { 1919 spec.results_.skipped = true; 1920 spec.finish(onComplete); 1921 return; 1922 } 1923 this.env.reporter.log('>> Jasmine Running ' + this.suite.description + ' ' + this.description + '...'); 1924 1925 spec.env.currentSpec = spec; 1926 1927 spec.addBeforesAndAftersToQueue(); 1928 1929 spec.queue.start(function () { 1930 spec.finish(onComplete); 1931 }); 1932 }; 1933 1934 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { 1935 var runner = this.env.currentRunner(); 1936 for (var suite = this.suite; suite; suite = suite.parentSuite) { 1937 for (var i = 0; i < suite.before_.length; i++) { 1938 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); 1939 } 1940 } 1941 for (var i = 0; i < runner.before_.length; i++) { 1942 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); 1943 } 1944 for (i = 0; i < this.afterCallbacks.length; i++) { 1945 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); 1946 } 1947 for (suite = this.suite; suite; suite = suite.parentSuite) { 1948 for (var i = 0; i < suite.after_.length; i++) { 1949 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); 1950 } 1951 } 1952 for (var i = 0; i < runner.after_.length; i++) { 1953 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); 1954 } 1955 }; 1956 1957 jasmine.Spec.prototype.explodes = function() { 1958 throw 'explodes function should not have been called'; 1959 }; 1960 1961 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { 1962 if (obj == undefined) { 1963 throw "spyOn could not find an object to spy upon for " + methodName + "()"; 1964 } 1965 1966 if (!ignoreMethodDoesntExist && obj[methodName] === undefined) { 1967 throw methodName + '() method does not exist'; 1968 } 1969 1970 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { 1971 throw new Error(methodName + ' has already been spied upon'); 1972 } 1973 1974 var spyObj = jasmine.createSpy(methodName); 1975 1976 this.spies_.push(spyObj); 1977 spyObj.baseObj = obj; 1978 spyObj.methodName = methodName; 1979 spyObj.originalValue = obj[methodName]; 1980 1981 obj[methodName] = spyObj; 1982 1983 return spyObj; 1984 }; 1985 1986 jasmine.Spec.prototype.removeAllSpies = function() { 1987 for (var i = 0; i < this.spies_.length; i++) { 1988 var spy = this.spies_[i]; 1989 spy.baseObj[spy.methodName] = spy.originalValue; 1990 } 1991 this.spies_ = []; 1992 }; 1993 1994 /** 1995 * Internal representation of a Jasmine suite. 1996 * 1997 * @constructor 1998 * @param {jasmine.Env} env 1999 * @param {String} description 2000 * @param {Function} specDefinitions 2001 * @param {jasmine.Suite} parentSuite 2002 */ 2003 jasmine.Suite = function(env, description, specDefinitions, parentSuite) { 2004 var self = this; 2005 self.id = env.nextSuiteId ? env.nextSuiteId() : null; 2006 self.description = description; 2007 self.queue = new jasmine.Queue(env); 2008 self.parentSuite = parentSuite; 2009 self.env = env; 2010 self.before_ = []; 2011 self.after_ = []; 2012 self.specs_ = []; 2013 }; 2014 2015 jasmine.Suite.prototype.getFullName = function() { 2016 var fullName = this.description; 2017 for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { 2018 fullName = parentSuite.description + ' ' + fullName; 2019 } 2020 return fullName; 2021 }; 2022 2023 jasmine.Suite.prototype.finish = function(onComplete) { 2024 this.env.reporter.reportSuiteResults(this); 2025 this.finished = true; 2026 if (typeof(onComplete) == 'function') { 2027 onComplete(); 2028 } 2029 }; 2030 2031 jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { 2032 beforeEachFunction.typeName = 'beforeEach'; 2033 this.before_.push(beforeEachFunction); 2034 }; 2035 2036 jasmine.Suite.prototype.afterEach = function(afterEachFunction) { 2037 afterEachFunction.typeName = 'afterEach'; 2038 this.after_.push(afterEachFunction); 2039 }; 2040 2041 jasmine.Suite.prototype.results = function() { 2042 return this.queue.results(); 2043 }; 2044 2045 jasmine.Suite.prototype.add = function(block) { 2046 if (block instanceof jasmine.Suite) { 2047 this.env.currentRunner().addSuite(block); 2048 } else { 2049 this.specs_.push(block); 2050 } 2051 this.queue.add(block); 2052 }; 2053 2054 jasmine.Suite.prototype.specs = function() { 2055 return this.specs_; 2056 }; 2057 2058 jasmine.Suite.prototype.execute = function(onComplete) { 2059 var self = this; 2060 this.queue.start(function () { 2061 self.finish(onComplete); 2062 }); 2063 }; 2064 jasmine.WaitsBlock = function(env, timeout, spec) { 2065 this.timeout = timeout; 2066 jasmine.Block.call(this, env, null, spec); 2067 }; 2068 2069 jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); 2070 2071 jasmine.WaitsBlock.prototype.execute = function (onComplete) { 2072 this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); 2073 this.env.setTimeout(function () { 2074 onComplete(); 2075 }, this.timeout); 2076 }; 2077 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { 2078 this.timeout = timeout; 2079 this.latchFunction = latchFunction; 2080 this.message = message; 2081 this.totalTimeSpentWaitingForLatch = 0; 2082 jasmine.Block.call(this, env, null, spec); 2083 }; 2084 2085 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); 2086 2087 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; 2088 2089 jasmine.WaitsForBlock.prototype.execute = function (onComplete) { 2090 var self = this; 2091 self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); 2092 var latchFunctionResult; 2093 try { 2094 latchFunctionResult = self.latchFunction.apply(self.spec); 2095 } catch (e) { 2096 self.spec.fail(e); 2097 onComplete(); 2098 return; 2099 } 2100 2101 if (latchFunctionResult) { 2102 onComplete(); 2103 } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { 2104 var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); 2105 self.spec.fail({ 2106 name: 'timeout', 2107 message: message 2108 }); 2109 self.spec._next(); 2110 } else { 2111 self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; 2112 self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); 2113 } 2114 }; 2115 // Mock setTimeout, clearTimeout 2116 // Contributed by Pivotal Computer Systems, www.pivotalsf.com 2117 2118 jasmine.FakeTimer = function() { 2119 this.reset(); 2120 2121 var self = this; 2122 self.setTimeout = function(funcToCall, millis) { 2123 self.timeoutsMade++; 2124 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); 2125 return self.timeoutsMade; 2126 }; 2127 2128 self.setInterval = function(funcToCall, millis) { 2129 self.timeoutsMade++; 2130 self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); 2131 return self.timeoutsMade; 2132 }; 2133 2134 self.clearTimeout = function(timeoutKey) { 2135 self.scheduledFunctions[timeoutKey] = undefined; 2136 }; 2137 2138 self.clearInterval = function(timeoutKey) { 2139 self.scheduledFunctions[timeoutKey] = undefined; 2140 }; 2141 2142 }; 2143 2144 jasmine.FakeTimer.prototype.reset = function() { 2145 this.timeoutsMade = 0; 2146 this.scheduledFunctions = {}; 2147 this.nowMillis = 0; 2148 }; 2149 2150 jasmine.FakeTimer.prototype.tick = function(millis) { 2151 var oldMillis = this.nowMillis; 2152 var newMillis = oldMillis + millis; 2153 this.runFunctionsWithinRange(oldMillis, newMillis); 2154 this.nowMillis = newMillis; 2155 }; 2156 2157 jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { 2158 var scheduledFunc; 2159 var funcsToRun = []; 2160 for (var timeoutKey in this.scheduledFunctions) { 2161 scheduledFunc = this.scheduledFunctions[timeoutKey]; 2162 if (scheduledFunc != undefined && 2163 scheduledFunc.runAtMillis >= oldMillis && 2164 scheduledFunc.runAtMillis <= nowMillis) { 2165 funcsToRun.push(scheduledFunc); 2166 this.scheduledFunctions[timeoutKey] = undefined; 2167 } 2168 } 2169 2170 if (funcsToRun.length > 0) { 2171 funcsToRun.sort(function(a, b) { 2172 return a.runAtMillis - b.runAtMillis; 2173 }); 2174 for (var i = 0; i < funcsToRun.length; ++i) { 2175 try { 2176 var funcToRun = funcsToRun[i]; 2177 this.nowMillis = funcToRun.runAtMillis; 2178 funcToRun.funcToCall(); 2179 if (funcToRun.recurring) { 2180 this.scheduleFunction(funcToRun.timeoutKey, 2181 funcToRun.funcToCall, 2182 funcToRun.millis, 2183 true); 2184 } 2185 } catch(e) { 2186 } 2187 } 2188 this.runFunctionsWithinRange(oldMillis, nowMillis); 2189 } 2190 }; 2191 2192 jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { 2193 this.scheduledFunctions[timeoutKey] = { 2194 runAtMillis: this.nowMillis + millis, 2195 funcToCall: funcToCall, 2196 recurring: recurring, 2197 timeoutKey: timeoutKey, 2198 millis: millis 2199 }; 2200 }; 2201 2202 2203 jasmine.Clock = { 2204 defaultFakeTimer: new jasmine.FakeTimer(), 2205 2206 reset: function() { 2207 jasmine.Clock.assertInstalled(); 2208 jasmine.Clock.defaultFakeTimer.reset(); 2209 }, 2210 2211 tick: function(millis) { 2212 jasmine.Clock.assertInstalled(); 2213 jasmine.Clock.defaultFakeTimer.tick(millis); 2214 }, 2215 2216 runFunctionsWithinRange: function(oldMillis, nowMillis) { 2217 jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); 2218 }, 2219 2220 scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { 2221 jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); 2222 }, 2223 2224 useMock: function() { 2225 var spec = jasmine.getEnv().currentSpec; 2226 spec.after(jasmine.Clock.uninstallMock); 2227 2228 jasmine.Clock.installMock(); 2229 }, 2230 2231 installMock: function() { 2232 jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; 2233 }, 2234 2235 uninstallMock: function() { 2236 jasmine.Clock.assertInstalled(); 2237 jasmine.Clock.installed = jasmine.Clock.real; 2238 }, 2239 2240 real: { 2241 setTimeout: window.setTimeout, 2242 clearTimeout: window.clearTimeout, 2243 setInterval: window.setInterval, 2244 clearInterval: window.clearInterval 2245 }, 2246 2247 assertInstalled: function() { 2248 if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) { 2249 throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); 2250 } 2251 }, 2252 2253 installed: null 2254 }; 2255 jasmine.Clock.installed = jasmine.Clock.real; 2256 2257 //else for IE support 2258 window.setTimeout = function(funcToCall, millis) { 2259 if (jasmine.Clock.installed.setTimeout.apply) { 2260 return jasmine.Clock.installed.setTimeout.apply(this, arguments); 2261 } else { 2262 return jasmine.Clock.installed.setTimeout(funcToCall, millis); 2263 } 2264 }; 2265 2266 window.setInterval = function(funcToCall, millis) { 2267 if (jasmine.Clock.installed.setInterval.apply) { 2268 return jasmine.Clock.installed.setInterval.apply(this, arguments); 2269 } else { 2270 return jasmine.Clock.installed.setInterval(funcToCall, millis); 2271 } 2272 }; 2273 2274 window.clearTimeout = function(timeoutKey) { 2275 if (jasmine.Clock.installed.clearTimeout.apply) { 2276 return jasmine.Clock.installed.clearTimeout.apply(this, arguments); 2277 } else { 2278 return jasmine.Clock.installed.clearTimeout(timeoutKey); 2279 } 2280 }; 2281 2282 window.clearInterval = function(timeoutKey) { 2283 if (jasmine.Clock.installed.clearTimeout.apply) { 2284 return jasmine.Clock.installed.clearInterval.apply(this, arguments); 2285 } else { 2286 return jasmine.Clock.installed.clearInterval(timeoutKey); 2287 } 2288 }; 2289 2290