1
var isCommonJS = typeof window == "undefined" && typeof exports == "object";
4
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
9
if (isCommonJS) exports.jasmine = jasmine;
13
jasmine.unimplementedMethod_ = function() {
14
throw new Error("unimplemented method");
18
* Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code> is just
19
* a plain old variable and may be redefined by somebody else.
23
jasmine.undefined = jasmine.___undefined___;
26
* Show diagnostic messages in the console if set to true
29
jasmine.VERBOSE = false;
32
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
35
jasmine.DEFAULT_UPDATE_INTERVAL = 250;
38
* Maximum levels of nesting that will be included when an object is pretty-printed
40
jasmine.MAX_PRETTY_PRINT_DEPTH = 40;
43
* Default timeout interval in milliseconds for waitsFor() blocks.
45
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
48
* By default exceptions thrown in the context of a test are caught by jasmine so that it can run the remaining tests in the suite.
49
* Set to false to let the exception bubble up in the browser.
52
jasmine.CATCH_EXCEPTIONS = true;
54
jasmine.getGlobal = function() {
55
function getGlobal() {
63
* Allows for bound functions to be compared. Internal use only.
67
* @param base {Object} bound 'this' for the function
68
* @param name {Function} function to find
70
jasmine.bindOriginal_ = function(base, name) {
71
var original = base[name];
74
return original.apply(base, arguments);
78
return jasmine.getGlobal()[name];
82
jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout');
83
jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout');
84
jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval');
85
jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval');
87
jasmine.MessageResult = function(values) {
90
this.trace = new Error(); // todo: test better
93
jasmine.MessageResult.prototype.toString = function() {
95
for (var i = 0; i < this.values.length; i++) {
96
if (i > 0) text += " ";
97
if (jasmine.isString_(this.values[i])) {
98
text += this.values[i];
100
text += jasmine.pp(this.values[i]);
106
jasmine.ExpectationResult = function(params) {
107
this.type = 'expect';
108
this.matcherName = params.matcherName;
109
this.passed_ = params.passed;
110
this.expected = params.expected;
111
this.actual = params.actual;
112
this.message = this.passed_ ? 'Passed.' : params.message;
114
var trace = (params.trace || new Error(this.message));
115
this.trace = this.passed_ ? '' : trace;
118
jasmine.ExpectationResult.prototype.toString = function () {
122
jasmine.ExpectationResult.prototype.passed = function () {
127
* Getter for the Jasmine environment. Ensures one gets created
129
jasmine.getEnv = function() {
130
var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
140
jasmine.isArray_ = function(value) {
141
return jasmine.isA_("Array", value);
150
jasmine.isString_ = function(value) {
151
return jasmine.isA_("String", value);
160
jasmine.isNumber_ = function(value) {
161
return jasmine.isA_("Number", value);
167
* @param {String} typeName
171
jasmine.isA_ = function(typeName, value) {
172
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
176
* Pretty printer for expecations. Takes any object and turns it into a human-readable string.
178
* @param value {Object} an object to be outputted
181
jasmine.pp = function(value) {
182
var stringPrettyPrinter = new jasmine.StringPrettyPrinter();
183
stringPrettyPrinter.format(value);
184
return stringPrettyPrinter.string;
188
* Returns true if the object is a DOM Node.
190
* @param {Object} obj object to check
193
jasmine.isDomNode = function(obj) {
194
return obj.nodeType > 0;
198
* Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter.
201
* // don't care about which function is passed in, as long as it's a function
202
* expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function));
204
* @param {Class} clazz
205
* @returns matchable object of the type clazz
207
jasmine.any = function(clazz) {
208
return new jasmine.Matchers.Any(clazz);
212
* Returns a matchable subset of a JSON object. For use in expectations when you don't care about all of the
213
* attributes on the object.
216
* // don't care about any other attributes than foo.
217
* expect(mySpy).toHaveBeenCalledWith(jasmine.objectContaining({foo: "bar"});
219
* @param sample {Object} sample
220
* @returns matchable object for the sample
222
jasmine.objectContaining = function (sample) {
223
return new jasmine.Matchers.ObjectContaining(sample);
227
* Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks.
229
* Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine
230
* expectation syntax. Spies can be checked if they were called or not and what the calling params were.
232
* A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs).
234
* Spies are torn down at the end of every spec.
236
* Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj.
240
* var myStub = jasmine.createSpy('myStub'); // can be used anywhere
244
* not: function(bool) { return !bool; }
247
* // actual foo.not will not be called, execution stops
250
// foo.not spied upon, execution will continue to implementation
251
* spyOn(foo, 'not').andCallThrough();
255
* not: function(bool) { return !bool; }
258
* // foo.not(val) will return val
259
* spyOn(foo, 'not').andCallFake(function(value) {return value;});
263
* expect(foo.not).toHaveBeenCalled();
264
* expect(foo.not).toHaveBeenCalledWith(true);
267
* @see spyOn, jasmine.createSpy, jasmine.createSpyObj
268
* @param {String} name
270
jasmine.Spy = function(name) {
272
* The name of the spy, if provided.
274
this.identity = name || 'unknown';
276
* Is this Object a spy?
280
* The actual function this spy stubs.
282
this.plan = function() {
285
* Tracking of the most recent call to the spy.
287
* var mySpy = jasmine.createSpy('foo');
289
* mySpy.mostRecentCall.args = [1, 2];
291
this.mostRecentCall = {};
294
* Holds arguments for each call to the spy, indexed by call count
296
* var mySpy = jasmine.createSpy('foo');
299
* mySpy.mostRecentCall.args = [7, 8];
300
* mySpy.argsForCall[0] = [1, 2];
301
* mySpy.argsForCall[1] = [7, 8];
303
this.argsForCall = [];
308
* Tells a spy to call through to the actual implemenatation.
312
* bar: function() { // do some stuff }
315
* // defining a spy on an existing property: foo.bar
316
* spyOn(foo, 'bar').andCallThrough();
318
jasmine.Spy.prototype.andCallThrough = function() {
319
this.plan = this.originalValue;
324
* For setting the return value of a spy.
327
* // defining a spy from scratch: foo() returns 'baz'
328
* var foo = jasmine.createSpy('spy on foo').andReturn('baz');
330
* // defining a spy on an existing property: foo.bar() returns 'baz'
331
* spyOn(foo, 'bar').andReturn('baz');
333
* @param {Object} value
335
jasmine.Spy.prototype.andReturn = function(value) {
336
this.plan = function() {
343
* For throwing an exception when a spy is called.
346
* // defining a spy from scratch: foo() throws an exception w/ message 'ouch'
347
* var foo = jasmine.createSpy('spy on foo').andThrow('baz');
349
* // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch'
350
* spyOn(foo, 'bar').andThrow('baz');
352
* @param {String} exceptionMsg
354
jasmine.Spy.prototype.andThrow = function(exceptionMsg) {
355
this.plan = function() {
362
* Calls an alternate implementation when a spy is called.
365
* var baz = function() {
366
* // do some stuff, return something
368
* // defining a spy from scratch: foo() calls the function baz
369
* var foo = jasmine.createSpy('spy on foo').andCall(baz);
371
* // defining a spy on an existing property: foo.bar() calls an anonymnous function
372
* spyOn(foo, 'bar').andCall(function() { return 'baz';} );
374
* @param {Function} fakeFunc
376
jasmine.Spy.prototype.andCallFake = function(fakeFunc) {
377
this.plan = fakeFunc;
382
* Resets all of a spy's the tracking variables so that it can be used again.
389
* expect(foo.bar.callCount).toEqual(1);
393
* expect(foo.bar.callCount).toEqual(0);
395
jasmine.Spy.prototype.reset = function() {
396
this.wasCalled = false;
398
this.argsForCall = [];
400
this.mostRecentCall = {};
403
jasmine.createSpy = function(name) {
405
var spyObj = function() {
406
spyObj.wasCalled = true;
408
var args = jasmine.util.argsToArray(arguments);
409
spyObj.mostRecentCall.object = this;
410
spyObj.mostRecentCall.args = args;
411
spyObj.argsForCall.push(args);
412
spyObj.calls.push({object: this, args: args});
413
return spyObj.plan.apply(this, arguments);
416
var spy = new jasmine.Spy(name);
418
for (var prop in spy) {
419
spyObj[prop] = spy[prop];
428
* Determines whether an object is a spy.
430
* @param {jasmine.Spy|Object} putativeSpy
433
jasmine.isSpy = function(putativeSpy) {
434
return putativeSpy && putativeSpy.isSpy;
438
* Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something
441
* @param {String} baseName name of spy class
442
* @param {Array} methodNames array of names of methods to make spies
444
jasmine.createSpyObj = function(baseName, methodNames) {
445
if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
446
throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
449
for (var i = 0; i < methodNames.length; i++) {
450
obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]);
456
* All parameters are pretty-printed and concatenated together, then written to the current spec's output.
458
* Be careful not to leave calls to <code>jasmine.log</code> in production code.
460
jasmine.log = function() {
461
var spec = jasmine.getEnv().currentSpec;
462
spec.log.apply(spec, arguments);
466
* Function that installs a spy on an existing object's method name. Used within a Spec to create a spy.
471
* not: function(bool) { return !bool; }
473
* spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
475
* @see jasmine.createSpy
478
* @return {jasmine.Spy} a Jasmine spy that can be chained with all spy methods
480
var spyOn = function(obj, methodName) {
481
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
483
if (isCommonJS) exports.spyOn = spyOn;
486
* Creates a Jasmine spec that will be added to the current suite.
488
* // TODO: pending tests
491
* it('should be true', function() {
492
* expect(true).toEqual(true);
495
* @param {String} desc description of this specification
496
* @param {Function} func defines the preconditions and expectations of the spec
498
var it = function(desc, func) {
499
return jasmine.getEnv().it(desc, func);
501
if (isCommonJS) exports.it = it;
504
* Creates a <em>disabled</em> Jasmine spec.
506
* A convenience method that allows existing specs to be disabled temporarily during development.
508
* @param {String} desc description of this specification
509
* @param {Function} func defines the preconditions and expectations of the spec
511
var xit = function(desc, func) {
512
return jasmine.getEnv().xit(desc, func);
514
if (isCommonJS) exports.xit = xit;
517
* Starts a chain for a Jasmine expectation.
519
* It is passed an Object that is the actual value and should chain to one of the many
520
* jasmine.Matchers functions.
522
* @param {Object} actual Actual value to test against and expected value
523
* @return {jasmine.Matchers}
525
var expect = function(actual) {
526
return jasmine.getEnv().currentSpec.expect(actual);
528
if (isCommonJS) exports.expect = expect;
531
* Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
533
* @param {Function} func Function that defines part of a jasmine spec.
535
var runs = function(func) {
536
jasmine.getEnv().currentSpec.runs(func);
538
if (isCommonJS) exports.runs = runs;
541
* Waits a fixed time period before moving to the next block.
543
* @deprecated Use waitsFor() instead
544
* @param {Number} timeout milliseconds to wait
546
var waits = function(timeout) {
547
jasmine.getEnv().currentSpec.waits(timeout);
549
if (isCommonJS) exports.waits = waits;
552
* Waits for the latchFunction to return true before proceeding to the next block.
554
* @param {Function} latchFunction
555
* @param {String} optional_timeoutMessage
556
* @param {Number} optional_timeout
558
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
559
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
561
if (isCommonJS) exports.waitsFor = waitsFor;
564
* A function that is called before each spec in a suite.
566
* Used for spec setup, including validating assumptions.
568
* @param {Function} beforeEachFunction
570
var beforeEach = function(beforeEachFunction) {
571
jasmine.getEnv().beforeEach(beforeEachFunction);
573
if (isCommonJS) exports.beforeEach = beforeEach;
576
* A function that is called after each spec in a suite.
578
* Used for restoring any state that is hijacked during spec execution.
580
* @param {Function} afterEachFunction
582
var afterEach = function(afterEachFunction) {
583
jasmine.getEnv().afterEach(afterEachFunction);
585
if (isCommonJS) exports.afterEach = afterEach;
588
* Defines a suite of specifications.
590
* Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared
591
* are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization
592
* of setup in some tests.
595
* // TODO: a simple suite
597
* // TODO: a simple suite with a nested describe block
599
* @param {String} description A string, usually the class under test.
600
* @param {Function} specDefinitions function that defines several specs.
602
var describe = function(description, specDefinitions) {
603
return jasmine.getEnv().describe(description, specDefinitions);
605
if (isCommonJS) exports.describe = describe;
608
* Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
610
* @param {String} description A string, usually the class under test.
611
* @param {Function} specDefinitions function that defines several specs.
613
var xdescribe = function(description, specDefinitions) {
614
return jasmine.getEnv().xdescribe(description, specDefinitions);
616
if (isCommonJS) exports.xdescribe = xdescribe;
619
// Provide the XMLHttpRequest class for IE 5.x-6.x:
620
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
629
var xhr = tryIt(function() {
630
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
633
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
636
return new ActiveXObject("Msxml2.XMLHTTP");
639
return new ActiveXObject("Microsoft.XMLHTTP");
642
if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
652
* Declare that a child class inherit it's prototype from the parent class.
655
* @param {Function} childClass
656
* @param {Function} parentClass
658
jasmine.util.inherit = function(childClass, parentClass) {
662
var subclass = function() {
664
subclass.prototype = parentClass.prototype;
665
childClass.prototype = new subclass();
668
jasmine.util.formatException = function(e) {
673
else if (e.lineNumber) {
674
lineNumber = e.lineNumber;
682
else if (e.fileName) {
686
var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString();
688
if (file && lineNumber) {
689
message += ' in ' + file + ' (line ' + lineNumber + ')';
695
jasmine.util.htmlEscape = function(str) {
696
if (!str) return str;
697
return str.replace(/&/g, '&')
698
.replace(/</g, '<')
699
.replace(/>/g, '>');
702
jasmine.util.argsToArray = function(args) {
703
var arrayOfArgs = [];
704
for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
708
jasmine.util.extend = function(destination, source) {
709
for (var property in source) destination[property] = source[property];
714
* Environment for Jasmine
718
jasmine.Env = function() {
719
this.currentSpec = null;
720
this.currentSuite = null;
721
this.currentRunner_ = new jasmine.Runner(this);
723
this.reporter = new jasmine.MultiReporter();
725
this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
726
this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
728
this.specFilter = function() {
732
this.nextSpecId_ = 0;
733
this.nextSuiteId_ = 0;
734
this.equalityTesters_ = [];
737
this.matchersClass = function() {
738
jasmine.Matchers.apply(this, arguments);
740
jasmine.util.inherit(this.matchersClass, jasmine.Matchers);
742
jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass);
746
jasmine.Env.prototype.setTimeout = jasmine.setTimeout;
747
jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
748
jasmine.Env.prototype.setInterval = jasmine.setInterval;
749
jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
752
* @returns an object containing jasmine version build info, if set.
754
jasmine.Env.prototype.version = function () {
755
if (jasmine.version_) {
756
return jasmine.version_;
758
throw new Error('Version not set');
763
* @returns string containing jasmine version build info, if set.
765
jasmine.Env.prototype.versionString = function() {
766
if (!jasmine.version_) {
767
return "version unknown";
770
var version = this.version();
771
var versionString = version.major + "." + version.minor + "." + version.build;
772
if (version.release_candidate) {
773
versionString += ".rc" + version.release_candidate;
775
versionString += " revision " + version.revision;
776
return versionString;
780
* @returns a sequential integer starting at 0
782
jasmine.Env.prototype.nextSpecId = function () {
783
return this.nextSpecId_++;
787
* @returns a sequential integer starting at 0
789
jasmine.Env.prototype.nextSuiteId = function () {
790
return this.nextSuiteId_++;
794
* Register a reporter to receive status updates from Jasmine.
795
* @param {jasmine.Reporter} reporter An object which will receive status updates.
797
jasmine.Env.prototype.addReporter = function(reporter) {
798
this.reporter.addReporter(reporter);
801
jasmine.Env.prototype.execute = function() {
802
this.currentRunner_.execute();
805
jasmine.Env.prototype.describe = function(description, specDefinitions) {
806
var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite);
808
var parentSuite = this.currentSuite;
810
parentSuite.add(suite);
812
this.currentRunner_.add(suite);
815
this.currentSuite = suite;
817
var declarationError = null;
819
specDefinitions.call(suite);
821
declarationError = e;
824
if (declarationError) {
825
this.it("encountered a declaration exception", function() {
826
throw declarationError;
830
this.currentSuite = parentSuite;
835
jasmine.Env.prototype.beforeEach = function(beforeEachFunction) {
836
if (this.currentSuite) {
837
this.currentSuite.beforeEach(beforeEachFunction);
839
this.currentRunner_.beforeEach(beforeEachFunction);
843
jasmine.Env.prototype.currentRunner = function () {
844
return this.currentRunner_;
847
jasmine.Env.prototype.afterEach = function(afterEachFunction) {
848
if (this.currentSuite) {
849
this.currentSuite.afterEach(afterEachFunction);
851
this.currentRunner_.afterEach(afterEachFunction);
856
jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) {
858
execute: function() {
863
jasmine.Env.prototype.it = function(description, func) {
864
var spec = new jasmine.Spec(this, this.currentSuite, description);
865
this.currentSuite.add(spec);
866
this.currentSpec = spec;
875
jasmine.Env.prototype.xit = function(desc, func) {
877
id: this.nextSpecId(),
883
jasmine.Env.prototype.compareRegExps_ = function(a, b, mismatchKeys, mismatchValues) {
884
if (a.source != b.source)
885
mismatchValues.push("expected pattern /" + b.source + "/ is not equal to the pattern /" + a.source + "/");
887
if (a.ignoreCase != b.ignoreCase)
888
mismatchValues.push("expected modifier i was" + (b.ignoreCase ? " " : " not ") + "set and does not equal the origin modifier");
890
if (a.global != b.global)
891
mismatchValues.push("expected modifier g was" + (b.global ? " " : " not ") + "set and does not equal the origin modifier");
893
if (a.multiline != b.multiline)
894
mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier");
896
if (a.sticky != b.sticky)
897
mismatchValues.push("expected modifier y was" + (b.sticky ? " " : " not ") + "set and does not equal the origin modifier");
899
return (mismatchValues.length === 0);
902
jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) {
903
if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) {
907
a.__Jasmine_been_here_before__ = b;
908
b.__Jasmine_been_here_before__ = a;
910
var hasKey = function(obj, keyName) {
911
return obj !== null && obj[keyName] !== jasmine.undefined;
914
for (var property in b) {
915
if (!hasKey(a, property) && hasKey(b, property)) {
916
mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
919
for (property in a) {
920
if (!hasKey(b, property) && hasKey(a, property)) {
921
mismatchKeys.push("expected missing key '" + property + "', but present in actual.");
924
for (property in b) {
925
if (property == '__Jasmine_been_here_before__') continue;
926
if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) {
927
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.");
931
if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) {
932
mismatchValues.push("arrays were not the same length");
935
delete a.__Jasmine_been_here_before__;
936
delete b.__Jasmine_been_here_before__;
937
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
940
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
941
mismatchKeys = mismatchKeys || [];
942
mismatchValues = mismatchValues || [];
944
for (var i = 0; i < this.equalityTesters_.length; i++) {
945
var equalityTester = this.equalityTesters_[i];
946
var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
947
if (result !== jasmine.undefined) return result;
950
if (a === b) return true;
952
if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) {
953
return (a == jasmine.undefined && b == jasmine.undefined);
956
if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
960
if (a instanceof Date && b instanceof Date) {
961
return a.getTime() == b.getTime();
964
if (a.jasmineMatches) {
965
return a.jasmineMatches(b);
968
if (b.jasmineMatches) {
969
return b.jasmineMatches(a);
972
if (a instanceof jasmine.Matchers.ObjectContaining) {
976
if (b instanceof jasmine.Matchers.ObjectContaining) {
980
if (jasmine.isString_(a) && jasmine.isString_(b)) {
984
if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
988
if (a instanceof RegExp && b instanceof RegExp) {
989
return this.compareRegExps_(a, b, mismatchKeys, mismatchValues);
992
if (typeof a === "object" && typeof b === "object") {
993
return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
1000
jasmine.Env.prototype.contains_ = function(haystack, needle) {
1001
if (jasmine.isArray_(haystack)) {
1002
for (var i = 0; i < haystack.length; i++) {
1003
if (this.equals_(haystack[i], needle)) return true;
1007
return haystack.indexOf(needle) >= 0;
1010
jasmine.Env.prototype.addEqualityTester = function(equalityTester) {
1011
this.equalityTesters_.push(equalityTester);
1013
/** No-op base class for Jasmine reporters.
1017
jasmine.Reporter = function() {
1020
//noinspection JSUnusedLocalSymbols
1021
jasmine.Reporter.prototype.reportRunnerStarting = function(runner) {
1024
//noinspection JSUnusedLocalSymbols
1025
jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
1028
//noinspection JSUnusedLocalSymbols
1029
jasmine.Reporter.prototype.reportSuiteResults = function(suite) {
1032
//noinspection JSUnusedLocalSymbols
1033
jasmine.Reporter.prototype.reportSpecStarting = function(spec) {
1036
//noinspection JSUnusedLocalSymbols
1037
jasmine.Reporter.prototype.reportSpecResults = function(spec) {
1040
//noinspection JSUnusedLocalSymbols
1041
jasmine.Reporter.prototype.log = function(str) {
1045
* Blocks are functions with executable code that make up a spec.
1048
* @param {jasmine.Env} env
1049
* @param {Function} func
1050
* @param {jasmine.Spec} spec
1052
jasmine.Block = function(env, func, spec) {
1058
jasmine.Block.prototype.execute = function(onComplete) {
1059
if (!jasmine.CATCH_EXCEPTIONS) {
1060
this.func.apply(this.spec);
1064
this.func.apply(this.spec);
1071
/** JavaScript API reporter.
1075
jasmine.JsApiReporter = function() {
1076
this.started = false;
1077
this.finished = false;
1082
jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) {
1083
this.started = true;
1084
var suites = runner.topLevelSuites();
1085
for (var i = 0; i < suites.length; i++) {
1086
var suite = suites[i];
1087
this.suites_.push(this.summarize_(suite));
1091
jasmine.JsApiReporter.prototype.suites = function() {
1092
return this.suites_;
1095
jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) {
1096
var isSuite = suiteOrSpec instanceof jasmine.Suite;
1099
name: suiteOrSpec.description,
1100
type: isSuite ? 'suite' : 'spec',
1105
var children = suiteOrSpec.children();
1106
for (var i = 0; i < children.length; i++) {
1107
summary.children.push(this.summarize_(children[i]));
1113
jasmine.JsApiReporter.prototype.results = function() {
1114
return this.results_;
1117
jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) {
1118
return this.results_[specId];
1121
//noinspection JSUnusedLocalSymbols
1122
jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) {
1123
this.finished = true;
1126
//noinspection JSUnusedLocalSymbols
1127
jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) {
1130
//noinspection JSUnusedLocalSymbols
1131
jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) {
1132
this.results_[spec.id] = {
1133
messages: spec.results().getItems(),
1134
result: spec.results().failedCount > 0 ? "failed" : "passed"
1138
//noinspection JSUnusedLocalSymbols
1139
jasmine.JsApiReporter.prototype.log = function(str) {
1142
jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){
1144
for (var i = 0; i < specIds.length; i++) {
1145
var specId = specIds[i];
1146
results[specId] = this.summarizeResult_(this.results_[specId]);
1151
jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){
1152
var summaryMessages = [];
1153
var messagesLength = result.messages.length;
1154
for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) {
1155
var resultMessage = result.messages[messageIndex];
1156
summaryMessages.push({
1157
text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined,
1158
passed: resultMessage.passed ? resultMessage.passed() : true,
1159
type: resultMessage.type,
1160
message: resultMessage.message,
1162
stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined
1168
result : result.result,
1169
messages : summaryMessages
1175
* @param {jasmine.Env} env
1177
* @param {jasmine.Spec} spec
1179
jasmine.Matchers = function(env, actual, spec, opt_isNot) {
1181
this.actual = actual;
1183
this.isNot = opt_isNot || false;
1184
this.reportWasCalled_ = false;
1187
// todo: @deprecated as of Jasmine 0.11, remove soon [xw]
1188
jasmine.Matchers.pp = function(str) {
1189
throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!");
1192
// todo: @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. [xw]
1193
jasmine.Matchers.prototype.report = function(result, failing_message, details) {
1194
throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs");
1197
jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) {
1198
for (var methodName in prototype) {
1199
if (methodName == 'report') continue;
1200
var orig = prototype[methodName];
1201
matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig);
1205
jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
1207
var matcherArgs = jasmine.util.argsToArray(arguments);
1208
var result = matcherFunction.apply(this, arguments);
1214
if (this.reportWasCalled_) return result;
1219
message = this.message.apply(this, arguments);
1220
if (jasmine.isArray_(message)) {
1221
message = message[this.isNot ? 1 : 0];
1224
var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
1225
message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate;
1226
if (matcherArgs.length > 0) {
1227
for (var i = 0; i < matcherArgs.length; i++) {
1228
if (i > 0) message += ",";
1229
message += " " + jasmine.pp(matcherArgs[i]);
1235
var expectationResult = new jasmine.ExpectationResult({
1236
matcherName: matcherName,
1238
expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0],
1239
actual: this.actual,
1242
this.spec.addMatcherResult(expectationResult);
1243
return jasmine.undefined;
1251
* toBe: compares the actual to the expected using ===
1254
jasmine.Matchers.prototype.toBe = function(expected) {
1255
return this.actual === expected;
1259
* toNotBe: compares the actual to the expected using !==
1261
* @deprecated as of 1.0. Use not.toBe() instead.
1263
jasmine.Matchers.prototype.toNotBe = function(expected) {
1264
return this.actual !== expected;
1268
* toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc.
1272
jasmine.Matchers.prototype.toEqual = function(expected) {
1273
return this.env.equals_(this.actual, expected);
1277
* toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual
1279
* @deprecated as of 1.0. Use not.toEqual() instead.
1281
jasmine.Matchers.prototype.toNotEqual = function(expected) {
1282
return !this.env.equals_(this.actual, expected);
1286
* Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes
1287
* a pattern or a String.
1291
jasmine.Matchers.prototype.toMatch = function(expected) {
1292
return new RegExp(expected).test(this.actual);
1296
* Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
1298
* @deprecated as of 1.0. Use not.toMatch() instead.
1300
jasmine.Matchers.prototype.toNotMatch = function(expected) {
1301
return !(new RegExp(expected).test(this.actual));
1305
* Matcher that compares the actual to jasmine.undefined.
1307
jasmine.Matchers.prototype.toBeDefined = function() {
1308
return (this.actual !== jasmine.undefined);
1312
* Matcher that compares the actual to jasmine.undefined.
1314
jasmine.Matchers.prototype.toBeUndefined = function() {
1315
return (this.actual === jasmine.undefined);
1319
* Matcher that compares the actual to null.
1321
jasmine.Matchers.prototype.toBeNull = function() {
1322
return (this.actual === null);
1326
* Matcher that compares the actual to NaN.
1328
jasmine.Matchers.prototype.toBeNaN = function() {
1329
this.message = function() {
1330
return [ "Expected " + jasmine.pp(this.actual) + " to be NaN." ];
1333
return (this.actual !== this.actual);
1337
* Matcher that boolean not-nots the actual.
1339
jasmine.Matchers.prototype.toBeTruthy = function() {
1340
return !!this.actual;
1345
* Matcher that boolean nots the actual.
1347
jasmine.Matchers.prototype.toBeFalsy = function() {
1348
return !this.actual;
1353
* Matcher that checks to see if the actual, a Jasmine spy, was called.
1355
jasmine.Matchers.prototype.toHaveBeenCalled = function() {
1356
if (arguments.length > 0) {
1357
throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
1360
if (!jasmine.isSpy(this.actual)) {
1361
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
1364
this.message = function() {
1366
"Expected spy " + this.actual.identity + " to have been called.",
1367
"Expected spy " + this.actual.identity + " not to have been called."
1371
return this.actual.wasCalled;
1374
/** @deprecated Use expect(xxx).toHaveBeenCalled() instead */
1375
jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled;
1378
* Matcher that checks to see if the actual, a Jasmine spy, was not called.
1380
* @deprecated Use expect(xxx).not.toHaveBeenCalled() instead
1382
jasmine.Matchers.prototype.wasNotCalled = function() {
1383
if (arguments.length > 0) {
1384
throw new Error('wasNotCalled does not take arguments');
1387
if (!jasmine.isSpy(this.actual)) {
1388
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
1391
this.message = function() {
1393
"Expected spy " + this.actual.identity + " to not have been called.",
1394
"Expected spy " + this.actual.identity + " to have been called."
1398
return !this.actual.wasCalled;
1402
* Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
1407
jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
1408
var expectedArgs = jasmine.util.argsToArray(arguments);
1409
if (!jasmine.isSpy(this.actual)) {
1410
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
1412
this.message = function() {
1413
var invertedMessage = "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was.";
1414
var positiveMessage = "";
1415
if (this.actual.callCount === 0) {
1416
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.";
1418
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '')
1420
return [positiveMessage, invertedMessage];
1423
return this.env.contains_(this.actual.argsForCall, expectedArgs);
1426
/** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */
1427
jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith;
1429
/** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */
1430
jasmine.Matchers.prototype.wasNotCalledWith = function() {
1431
var expectedArgs = jasmine.util.argsToArray(arguments);
1432
if (!jasmine.isSpy(this.actual)) {
1433
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
1436
this.message = function() {
1438
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
1439
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
1443
return !this.env.contains_(this.actual.argsForCall, expectedArgs);
1447
* Matcher that checks that the expected item is an element in the actual Array.
1449
* @param {Object} expected
1451
jasmine.Matchers.prototype.toContain = function(expected) {
1452
return this.env.contains_(this.actual, expected);
1456
* Matcher that checks that the expected item is NOT an element in the actual Array.
1458
* @param {Object} expected
1459
* @deprecated as of 1.0. Use not.toContain() instead.
1461
jasmine.Matchers.prototype.toNotContain = function(expected) {
1462
return !this.env.contains_(this.actual, expected);
1465
jasmine.Matchers.prototype.toBeLessThan = function(expected) {
1466
return this.actual < expected;
1469
jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
1470
return this.actual > expected;
1474
* Matcher that checks that the expected item is equal to the actual item
1475
* up to a given level of decimal precision (default 2).
1477
* @param {Number} expected
1478
* @param {Number} precision, as number of decimal places
1480
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
1481
if (!(precision === 0)) {
1482
precision = precision || 2;
1484
return Math.abs(expected - this.actual) < (Math.pow(10, -precision) / 2);
1488
* Matcher that checks that the expected exception was thrown by the actual.
1490
* @param {String} [expected]
1492
jasmine.Matchers.prototype.toThrow = function(expected) {
1495
if (typeof this.actual != 'function') {
1496
throw new Error('Actual is not a function');
1504
result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
1507
var not = this.isNot ? "not " : "";
1509
this.message = function() {
1510
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
1511
return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
1513
return "Expected function to throw an exception.";
1520
jasmine.Matchers.Any = function(expectedClass) {
1521
this.expectedClass = expectedClass;
1524
jasmine.Matchers.Any.prototype.jasmineMatches = function(other) {
1525
if (this.expectedClass == String) {
1526
return typeof other == 'string' || other instanceof String;
1529
if (this.expectedClass == Number) {
1530
return typeof other == 'number' || other instanceof Number;
1533
if (this.expectedClass == Function) {
1534
return typeof other == 'function' || other instanceof Function;
1537
if (this.expectedClass == Object) {
1538
return typeof other == 'object';
1541
return other instanceof this.expectedClass;
1544
jasmine.Matchers.Any.prototype.jasmineToString = function() {
1545
return '<jasmine.any(' + this.expectedClass + ')>';
1548
jasmine.Matchers.ObjectContaining = function (sample) {
1549
this.sample = sample;
1552
jasmine.Matchers.ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) {
1553
mismatchKeys = mismatchKeys || [];
1554
mismatchValues = mismatchValues || [];
1556
var env = jasmine.getEnv();
1558
var hasKey = function(obj, keyName) {
1559
return obj != null && obj[keyName] !== jasmine.undefined;
1562
for (var property in this.sample) {
1563
if (!hasKey(other, property) && hasKey(this.sample, property)) {
1564
mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
1566
else if (!env.equals_(this.sample[property], other[property], mismatchKeys, mismatchValues)) {
1567
mismatchValues.push("'" + property + "' was '" + (other[property] ? jasmine.util.htmlEscape(other[property].toString()) : other[property]) + "' in expected, but was '" + (this.sample[property] ? jasmine.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + "' in actual.");
1571
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
1574
jasmine.Matchers.ObjectContaining.prototype.jasmineToString = function () {
1575
return "<jasmine.objectContaining(" + jasmine.pp(this.sample) + ")>";
1577
// Mock setTimeout, clearTimeout
1578
// Contributed by Pivotal Computer Systems, www.pivotalsf.com
1580
jasmine.FakeTimer = function() {
1584
self.setTimeout = function(funcToCall, millis) {
1585
self.timeoutsMade++;
1586
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false);
1587
return self.timeoutsMade;
1590
self.setInterval = function(funcToCall, millis) {
1591
self.timeoutsMade++;
1592
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true);
1593
return self.timeoutsMade;
1596
self.clearTimeout = function(timeoutKey) {
1597
self.scheduledFunctions[timeoutKey] = jasmine.undefined;
1600
self.clearInterval = function(timeoutKey) {
1601
self.scheduledFunctions[timeoutKey] = jasmine.undefined;
1606
jasmine.FakeTimer.prototype.reset = function() {
1607
this.timeoutsMade = 0;
1608
this.scheduledFunctions = {};
1612
jasmine.FakeTimer.prototype.tick = function(millis) {
1613
var oldMillis = this.nowMillis;
1614
var newMillis = oldMillis + millis;
1615
this.runFunctionsWithinRange(oldMillis, newMillis);
1616
this.nowMillis = newMillis;
1619
jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) {
1621
var funcsToRun = [];
1622
for (var timeoutKey in this.scheduledFunctions) {
1623
scheduledFunc = this.scheduledFunctions[timeoutKey];
1624
if (scheduledFunc != jasmine.undefined &&
1625
scheduledFunc.runAtMillis >= oldMillis &&
1626
scheduledFunc.runAtMillis <= nowMillis) {
1627
funcsToRun.push(scheduledFunc);
1628
this.scheduledFunctions[timeoutKey] = jasmine.undefined;
1632
if (funcsToRun.length > 0) {
1633
funcsToRun.sort(function(a, b) {
1634
return a.runAtMillis - b.runAtMillis;
1636
for (var i = 0; i < funcsToRun.length; ++i) {
1638
var funcToRun = funcsToRun[i];
1639
this.nowMillis = funcToRun.runAtMillis;
1640
funcToRun.funcToCall();
1641
if (funcToRun.recurring) {
1642
this.scheduleFunction(funcToRun.timeoutKey,
1643
funcToRun.funcToCall,
1650
this.runFunctionsWithinRange(oldMillis, nowMillis);
1654
jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) {
1655
this.scheduledFunctions[timeoutKey] = {
1656
runAtMillis: this.nowMillis + millis,
1657
funcToCall: funcToCall,
1658
recurring: recurring,
1659
timeoutKey: timeoutKey,
1668
defaultFakeTimer: new jasmine.FakeTimer(),
1671
jasmine.Clock.assertInstalled();
1672
jasmine.Clock.defaultFakeTimer.reset();
1675
tick: function(millis) {
1676
jasmine.Clock.assertInstalled();
1677
jasmine.Clock.defaultFakeTimer.tick(millis);
1680
runFunctionsWithinRange: function(oldMillis, nowMillis) {
1681
jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis);
1684
scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) {
1685
jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring);
1688
useMock: function() {
1689
if (!jasmine.Clock.isInstalled()) {
1690
var spec = jasmine.getEnv().currentSpec;
1691
spec.after(jasmine.Clock.uninstallMock);
1693
jasmine.Clock.installMock();
1697
installMock: function() {
1698
jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer;
1701
uninstallMock: function() {
1702
jasmine.Clock.assertInstalled();
1703
jasmine.Clock.installed = jasmine.Clock.real;
1707
setTimeout: jasmine.getGlobal().setTimeout,
1708
clearTimeout: jasmine.getGlobal().clearTimeout,
1709
setInterval: jasmine.getGlobal().setInterval,
1710
clearInterval: jasmine.getGlobal().clearInterval
1713
assertInstalled: function() {
1714
if (!jasmine.Clock.isInstalled()) {
1715
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
1719
isInstalled: function() {
1720
return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer;
1725
jasmine.Clock.installed = jasmine.Clock.real;
1727
//else for IE support
1728
jasmine.getGlobal().setTimeout = function(funcToCall, millis) {
1729
if (jasmine.Clock.installed.setTimeout.apply) {
1730
return jasmine.Clock.installed.setTimeout.apply(this, arguments);
1732
return jasmine.Clock.installed.setTimeout(funcToCall, millis);
1736
jasmine.getGlobal().setInterval = function(funcToCall, millis) {
1737
if (jasmine.Clock.installed.setInterval.apply) {
1738
return jasmine.Clock.installed.setInterval.apply(this, arguments);
1740
return jasmine.Clock.installed.setInterval(funcToCall, millis);
1744
jasmine.getGlobal().clearTimeout = function(timeoutKey) {
1745
if (jasmine.Clock.installed.clearTimeout.apply) {
1746
return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
1748
return jasmine.Clock.installed.clearTimeout(timeoutKey);
1752
jasmine.getGlobal().clearInterval = function(timeoutKey) {
1753
if (jasmine.Clock.installed.clearTimeout.apply) {
1754
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
1756
return jasmine.Clock.installed.clearInterval(timeoutKey);
1763
jasmine.MultiReporter = function() {
1764
this.subReporters_ = [];
1766
jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter);
1768
jasmine.MultiReporter.prototype.addReporter = function(reporter) {
1769
this.subReporters_.push(reporter);
1773
var functionNames = [
1774
"reportRunnerStarting",
1775
"reportRunnerResults",
1776
"reportSuiteResults",
1777
"reportSpecStarting",
1778
"reportSpecResults",
1781
for (var i = 0; i < functionNames.length; i++) {
1782
var functionName = functionNames[i];
1783
jasmine.MultiReporter.prototype[functionName] = (function(functionName) {
1785
for (var j = 0; j < this.subReporters_.length; j++) {
1786
var subReporter = this.subReporters_[j];
1787
if (subReporter[functionName]) {
1788
subReporter[functionName].apply(subReporter, arguments);
1796
* Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults
1800
jasmine.NestedResults = function() {
1802
* The total count of results
1804
this.totalCount = 0;
1806
* Number of passed results
1808
this.passedCount = 0;
1810
* Number of failed results
1812
this.failedCount = 0;
1814
* Was this suite/spec skipped?
1816
this.skipped = false;
1824
* Roll up the result counts.
1828
jasmine.NestedResults.prototype.rollupCounts = function(result) {
1829
this.totalCount += result.totalCount;
1830
this.passedCount += result.passedCount;
1831
this.failedCount += result.failedCount;
1835
* Adds a log message.
1836
* @param values Array of message parts which will be concatenated later.
1838
jasmine.NestedResults.prototype.log = function(values) {
1839
this.items_.push(new jasmine.MessageResult(values));
1843
* Getter for the results: message & results.
1845
jasmine.NestedResults.prototype.getItems = function() {
1850
* Adds a result, tracking counts (total, passed, & failed)
1851
* @param {jasmine.ExpectationResult|jasmine.NestedResults} result
1853
jasmine.NestedResults.prototype.addResult = function(result) {
1854
if (result.type != 'log') {
1855
if (result.items_) {
1856
this.rollupCounts(result);
1859
if (result.passed()) {
1866
this.items_.push(result);
1870
* @returns {Boolean} True if <b>everything</b> below passed
1872
jasmine.NestedResults.prototype.passed = function() {
1873
return this.passedCount === this.totalCount;
1876
* Base class for pretty printing for expectation results.
1878
jasmine.PrettyPrinter = function() {
1879
this.ppNestLevel_ = 0;
1883
* Formats a value in a nice, human-readable string.
1887
jasmine.PrettyPrinter.prototype.format = function(value) {
1888
this.ppNestLevel_++;
1890
if (value === jasmine.undefined) {
1891
this.emitScalar('undefined');
1892
} else if (value === null) {
1893
this.emitScalar('null');
1894
} else if (value === jasmine.getGlobal()) {
1895
this.emitScalar('<global>');
1896
} else if (value.jasmineToString) {
1897
this.emitScalar(value.jasmineToString());
1898
} else if (typeof value === 'string') {
1899
this.emitString(value);
1900
} else if (jasmine.isSpy(value)) {
1901
this.emitScalar("spy on " + value.identity);
1902
} else if (value instanceof RegExp) {
1903
this.emitScalar(value.toString());
1904
} else if (typeof value === 'function') {
1905
this.emitScalar('Function');
1906
} else if (typeof value.nodeType === 'number') {
1907
this.emitScalar('HTMLNode');
1908
} else if (value instanceof Date) {
1909
this.emitScalar('Date(' + value + ')');
1910
} else if (value.__Jasmine_been_here_before__) {
1911
this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>');
1912
} else if (jasmine.isArray_(value) || typeof value == 'object') {
1913
value.__Jasmine_been_here_before__ = true;
1914
if (jasmine.isArray_(value)) {
1915
this.emitArray(value);
1917
this.emitObject(value);
1919
delete value.__Jasmine_been_here_before__;
1921
this.emitScalar(value.toString());
1924
this.ppNestLevel_--;
1928
jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
1929
for (var property in obj) {
1930
if (!obj.hasOwnProperty(property)) continue;
1931
if (property == '__Jasmine_been_here_before__') continue;
1932
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
1933
obj.__lookupGetter__(property) !== null) : false);
1937
jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_;
1938
jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_;
1939
jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_;
1940
jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_;
1942
jasmine.StringPrettyPrinter = function() {
1943
jasmine.PrettyPrinter.call(this);
1947
jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter);
1949
jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) {
1953
jasmine.StringPrettyPrinter.prototype.emitString = function(value) {
1954
this.append("'" + value + "'");
1957
jasmine.StringPrettyPrinter.prototype.emitArray = function(array) {
1958
if (this.ppNestLevel_ > jasmine.MAX_PRETTY_PRINT_DEPTH) {
1959
this.append("Array");
1964
for (var i = 0; i < array.length; i++) {
1968
this.format(array[i]);
1973
jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) {
1974
if (this.ppNestLevel_ > jasmine.MAX_PRETTY_PRINT_DEPTH) {
1975
this.append("Object");
1983
this.iterateObject(obj, function(property, isGetter) {
1990
self.append(property);
1993
self.append('<getter>');
1995
self.format(obj[property]);
2002
jasmine.StringPrettyPrinter.prototype.append = function(value) {
2003
this.string += value;
2005
jasmine.Queue = function(env) {
2008
// parallel to blocks. each true value in this array means the block will
2009
// get executed even if we abort
2012
this.running = false;
2018
jasmine.Queue.prototype.addBefore = function(block, ensure) {
2019
if (ensure === jasmine.undefined) {
2023
this.blocks.unshift(block);
2024
this.ensured.unshift(ensure);
2027
jasmine.Queue.prototype.add = function(block, ensure) {
2028
if (ensure === jasmine.undefined) {
2032
this.blocks.push(block);
2033
this.ensured.push(ensure);
2036
jasmine.Queue.prototype.insertNext = function(block, ensure) {
2037
if (ensure === jasmine.undefined) {
2041
this.ensured.splice((this.index + this.offset + 1), 0, ensure);
2042
this.blocks.splice((this.index + this.offset + 1), 0, block);
2046
jasmine.Queue.prototype.start = function(onComplete) {
2047
this.running = true;
2048
this.onComplete = onComplete;
2052
jasmine.Queue.prototype.isRunning = function() {
2053
return this.running;
2056
jasmine.Queue.LOOP_DONT_RECURSE = true;
2058
jasmine.Queue.prototype.next_ = function() {
2065
if (self.index < self.blocks.length && !(this.abort && !this.ensured[self.index])) {
2066
var calledSynchronously = true;
2067
var completedSynchronously = false;
2069
var onComplete = function () {
2070
if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) {
2071
completedSynchronously = true;
2075
if (self.blocks[self.index].abort) {
2082
var now = new Date().getTime();
2083
if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
2084
self.env.lastUpdate = now;
2085
self.env.setTimeout(function() {
2089
if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) {
2096
self.blocks[self.index].execute(onComplete);
2098
calledSynchronously = false;
2099
if (completedSynchronously) {
2104
self.running = false;
2105
if (self.onComplete) {
2112
jasmine.Queue.prototype.results = function() {
2113
var results = new jasmine.NestedResults();
2114
for (var i = 0; i < this.blocks.length; i++) {
2115
if (this.blocks[i].results) {
2116
results.addResult(this.blocks[i].results());
2127
* @param {jasmine.Env} env
2129
jasmine.Runner = function(env) {
2132
self.queue = new jasmine.Queue(env);
2138
jasmine.Runner.prototype.execute = function() {
2140
if (self.env.reporter.reportRunnerStarting) {
2141
self.env.reporter.reportRunnerStarting(this);
2143
self.queue.start(function () {
2144
self.finishCallback();
2148
jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) {
2149
beforeEachFunction.typeName = 'beforeEach';
2150
this.before_.splice(0,0,beforeEachFunction);
2153
jasmine.Runner.prototype.afterEach = function(afterEachFunction) {
2154
afterEachFunction.typeName = 'afterEach';
2155
this.after_.splice(0,0,afterEachFunction);
2159
jasmine.Runner.prototype.finishCallback = function() {
2160
this.env.reporter.reportRunnerResults(this);
2163
jasmine.Runner.prototype.addSuite = function(suite) {
2164
this.suites_.push(suite);
2167
jasmine.Runner.prototype.add = function(block) {
2168
if (block instanceof jasmine.Suite) {
2169
this.addSuite(block);
2171
this.queue.add(block);
2174
jasmine.Runner.prototype.specs = function () {
2175
var suites = this.suites();
2177
for (var i = 0; i < suites.length; i++) {
2178
specs = specs.concat(suites[i].specs());
2183
jasmine.Runner.prototype.suites = function() {
2184
return this.suites_;
2187
jasmine.Runner.prototype.topLevelSuites = function() {
2188
var topLevelSuites = [];
2189
for (var i = 0; i < this.suites_.length; i++) {
2190
if (!this.suites_[i].parentSuite) {
2191
topLevelSuites.push(this.suites_[i]);
2194
return topLevelSuites;
2197
jasmine.Runner.prototype.results = function() {
2198
return this.queue.results();
2201
* Internal representation of a Jasmine specification, or test.
2204
* @param {jasmine.Env} env
2205
* @param {jasmine.Suite} suite
2206
* @param {String} description
2208
jasmine.Spec = function(env, suite, description) {
2210
throw new Error('jasmine.Env() required');
2213
throw new Error('jasmine.Suite() required');
2216
spec.id = env.nextSpecId ? env.nextSpecId() : null;
2219
spec.description = description;
2220
spec.queue = new jasmine.Queue(env);
2222
spec.afterCallbacks = [];
2225
spec.results_ = new jasmine.NestedResults();
2226
spec.results_.description = description;
2227
spec.matchersClass = null;
2230
jasmine.Spec.prototype.getFullName = function() {
2231
return this.suite.getFullName() + ' ' + this.description + '.';
2235
jasmine.Spec.prototype.results = function() {
2236
return this.results_;
2240
* All parameters are pretty-printed and concatenated together, then written to the spec's output.
2242
* Be careful not to leave calls to <code>jasmine.log</code> in production code.
2244
jasmine.Spec.prototype.log = function() {
2245
return this.results_.log(arguments);
2248
jasmine.Spec.prototype.runs = function (func) {
2249
var block = new jasmine.Block(this.env, func, this);
2250
this.addToQueue(block);
2254
jasmine.Spec.prototype.addToQueue = function (block) {
2255
if (this.queue.isRunning()) {
2256
this.queue.insertNext(block);
2258
this.queue.add(block);
2263
* @param {jasmine.ExpectationResult} result
2265
jasmine.Spec.prototype.addMatcherResult = function(result) {
2266
this.results_.addResult(result);
2269
jasmine.Spec.prototype.expect = function(actual) {
2270
var positive = new (this.getMatchersClass_())(this.env, actual, this);
2271
positive.not = new (this.getMatchersClass_())(this.env, actual, this, true);
2276
* Waits a fixed time period before moving to the next block.
2278
* @deprecated Use waitsFor() instead
2279
* @param {Number} timeout milliseconds to wait
2281
jasmine.Spec.prototype.waits = function(timeout) {
2282
var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this);
2283
this.addToQueue(waitsFunc);
2288
* Waits for the latchFunction to return true before proceeding to the next block.
2290
* @param {Function} latchFunction
2291
* @param {String} optional_timeoutMessage
2292
* @param {Number} optional_timeout
2294
jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
2295
var latchFunction_ = null;
2296
var optional_timeoutMessage_ = null;
2297
var optional_timeout_ = null;
2299
for (var i = 0; i < arguments.length; i++) {
2300
var arg = arguments[i];
2301
switch (typeof arg) {
2303
latchFunction_ = arg;
2306
optional_timeoutMessage_ = arg;
2309
optional_timeout_ = arg;
2314
var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this);
2315
this.addToQueue(waitsForFunc);
2319
jasmine.Spec.prototype.fail = function (e) {
2320
var expectationResult = new jasmine.ExpectationResult({
2322
message: e ? jasmine.util.formatException(e) : 'Exception',
2323
trace: { stack: e.stack }
2325
this.results_.addResult(expectationResult);
2328
jasmine.Spec.prototype.getMatchersClass_ = function() {
2329
return this.matchersClass || this.env.matchersClass;
2332
jasmine.Spec.prototype.addMatchers = function(matchersPrototype) {
2333
var parent = this.getMatchersClass_();
2334
var newMatchersClass = function() {
2335
parent.apply(this, arguments);
2337
jasmine.util.inherit(newMatchersClass, parent);
2338
jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass);
2339
this.matchersClass = newMatchersClass;
2342
jasmine.Spec.prototype.finishCallback = function() {
2343
this.env.reporter.reportSpecResults(this);
2346
jasmine.Spec.prototype.finish = function(onComplete) {
2347
this.removeAllSpies();
2348
this.finishCallback();
2354
jasmine.Spec.prototype.after = function(doAfter) {
2355
if (this.queue.isRunning()) {
2356
this.queue.add(new jasmine.Block(this.env, doAfter, this), true);
2358
this.afterCallbacks.unshift(doAfter);
2362
jasmine.Spec.prototype.execute = function(onComplete) {
2364
if (!spec.env.specFilter(spec)) {
2365
spec.results_.skipped = true;
2366
spec.finish(onComplete);
2370
this.env.reporter.reportSpecStarting(this);
2372
spec.env.currentSpec = spec;
2374
spec.addBeforesAndAftersToQueue();
2376
spec.queue.start(function () {
2377
spec.finish(onComplete);
2381
jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
2382
var runner = this.env.currentRunner();
2385
for (var suite = this.suite; suite; suite = suite.parentSuite) {
2386
for (i = 0; i < suite.before_.length; i++) {
2387
this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this));
2390
for (i = 0; i < runner.before_.length; i++) {
2391
this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this));
2393
for (i = 0; i < this.afterCallbacks.length; i++) {
2394
this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this), true);
2396
for (suite = this.suite; suite; suite = suite.parentSuite) {
2397
for (i = 0; i < suite.after_.length; i++) {
2398
this.queue.add(new jasmine.Block(this.env, suite.after_[i], this), true);
2401
for (i = 0; i < runner.after_.length; i++) {
2402
this.queue.add(new jasmine.Block(this.env, runner.after_[i], this), true);
2406
jasmine.Spec.prototype.explodes = function() {
2407
throw 'explodes function should not have been called';
2410
jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) {
2411
if (obj == jasmine.undefined) {
2412
throw "spyOn could not find an object to spy upon for " + methodName + "()";
2415
if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) {
2416
throw methodName + '() method does not exist';
2419
if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) {
2420
throw new Error(methodName + ' has already been spied upon');
2423
var spyObj = jasmine.createSpy(methodName);
2425
this.spies_.push(spyObj);
2426
spyObj.baseObj = obj;
2427
spyObj.methodName = methodName;
2428
spyObj.originalValue = obj[methodName];
2430
obj[methodName] = spyObj;
2435
jasmine.Spec.prototype.removeAllSpies = function() {
2436
for (var i = 0; i < this.spies_.length; i++) {
2437
var spy = this.spies_[i];
2438
spy.baseObj[spy.methodName] = spy.originalValue;
2444
* Internal representation of a Jasmine suite.
2447
* @param {jasmine.Env} env
2448
* @param {String} description
2449
* @param {Function} specDefinitions
2450
* @param {jasmine.Suite} parentSuite
2452
jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
2454
self.id = env.nextSuiteId ? env.nextSuiteId() : null;
2455
self.description = description;
2456
self.queue = new jasmine.Queue(env);
2457
self.parentSuite = parentSuite;
2461
self.children_ = [];
2466
jasmine.Suite.prototype.getFullName = function() {
2467
var fullName = this.description;
2468
for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
2469
fullName = parentSuite.description + ' ' + fullName;
2474
jasmine.Suite.prototype.finish = function(onComplete) {
2475
this.env.reporter.reportSuiteResults(this);
2476
this.finished = true;
2477
if (typeof(onComplete) == 'function') {
2482
jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
2483
beforeEachFunction.typeName = 'beforeEach';
2484
this.before_.unshift(beforeEachFunction);
2487
jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
2488
afterEachFunction.typeName = 'afterEach';
2489
this.after_.unshift(afterEachFunction);
2492
jasmine.Suite.prototype.results = function() {
2493
return this.queue.results();
2496
jasmine.Suite.prototype.add = function(suiteOrSpec) {
2497
this.children_.push(suiteOrSpec);
2498
if (suiteOrSpec instanceof jasmine.Suite) {
2499
this.suites_.push(suiteOrSpec);
2500
this.env.currentRunner().addSuite(suiteOrSpec);
2502
this.specs_.push(suiteOrSpec);
2504
this.queue.add(suiteOrSpec);
2507
jasmine.Suite.prototype.specs = function() {
2511
jasmine.Suite.prototype.suites = function() {
2512
return this.suites_;
2515
jasmine.Suite.prototype.children = function() {
2516
return this.children_;
2519
jasmine.Suite.prototype.execute = function(onComplete) {
2521
this.queue.start(function () {
2522
self.finish(onComplete);
2525
jasmine.WaitsBlock = function(env, timeout, spec) {
2526
this.timeout = timeout;
2527
jasmine.Block.call(this, env, null, spec);
2530
jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
2532
jasmine.WaitsBlock.prototype.execute = function (onComplete) {
2533
if (jasmine.VERBOSE) {
2534
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
2536
this.env.setTimeout(function () {
2541
* A block which waits for some condition to become true, with timeout.
2544
* @extends jasmine.Block
2545
* @param {jasmine.Env} env The Jasmine environment.
2546
* @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
2547
* @param {Function} latchFunction A function which returns true when the desired condition has been met.
2548
* @param {String} message The message to display if the desired condition hasn't been met within the given time period.
2549
* @param {jasmine.Spec} spec The Jasmine spec.
2551
jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
2552
this.timeout = timeout || env.defaultTimeoutInterval;
2553
this.latchFunction = latchFunction;
2554
this.message = message;
2555
this.totalTimeSpentWaitingForLatch = 0;
2556
jasmine.Block.call(this, env, null, spec);
2558
jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
2560
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
2562
jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
2563
if (jasmine.VERBOSE) {
2564
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
2566
var latchFunctionResult;
2568
latchFunctionResult = this.latchFunction.apply(this.spec);
2575
if (latchFunctionResult) {
2577
} else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
2578
var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
2587
this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
2589
this.env.setTimeout(function() {
2590
self.execute(onComplete);
2591
}, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
2599
"revision": 1354556913