jasmine.js
22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
/*
* Jasmine internal classes & objects
*/
var Jasmine = {};
Jasmine.util = {};
/** @deprecated Use Jasmine.util instead */
Jasmine.Util = Jasmine.util;
Jasmine.util.inherit = function(childClass, parentClass) {
var subclass = function() { };
subclass.prototype = parentClass.prototype;
childClass.prototype = new subclass;
};
/*
* Holds results; allows for the results array to hold another Jasmine.NestedResults
*/
Jasmine.NestedResults = function() {
this.totalCount = 0;
this.passedCount = 0;
this.failedCount = 0;
this.results = [];
};
Jasmine.NestedResults.prototype.rollupCounts = function(result) {
this.totalCount += result.totalCount;
this.passedCount += result.passedCount;
this.failedCount += result.failedCount;
};
Jasmine.NestedResults.prototype.push = function(result) {
if (result.results) {
this.rollupCounts(result);
} else {
this.totalCount++;
if (result.passed) {
this.passedCount++;
} else {
this.failedCount++;
}
}
this.results.push(result);
};
Jasmine.NestedResults.prototype.passed = function() {
return this.passedCount === this.totalCount;
};
/*
* base for Runner & Suite: allows for a queue of functions to get executed, allowing for
* any one action to complete, including asynchronous calls, before going to the next
* action.
*
**/
Jasmine.ActionCollection = function() {
this.actions = [];
this.index = 0;
this.finished = false;
this.results = new Jasmine.NestedResults();
};
Jasmine.ActionCollection.prototype.finish = function() {
if (this.finishCallback) {
this.finishCallback();
}
this.finished = true;
};
Jasmine.ActionCollection.prototype.report = function(result) {
this.results.push(result);
};
Jasmine.ActionCollection.prototype.execute = function() {
if (this.actions.length > 0) {
this.next();
}
};
Jasmine.ActionCollection.prototype.getCurrentAction = function() {
return this.actions[this.index];
};
Jasmine.ActionCollection.prototype.next = function() {
if (this.index >= this.actions.length) {
this.finish();
return;
}
var currentAction = this.getCurrentAction();
currentAction.execute(this);
if (currentAction.afterCallbacks) {
for (var i = 0; i < currentAction.afterCallbacks.length; i++) {
try {
currentAction.afterCallbacks[i]();
} catch (e) {
alert(e);
}
}
}
this.waitForDone(currentAction);
};
Jasmine.ActionCollection.prototype.waitForDone = function(action) {
var self = this;
var afterExecute = function() {
self.report(action.results);
self.index++;
self.next();
};
if (action.finished) {
afterExecute();
return;
}
var id = setInterval(function() {
if (action.finished) {
clearInterval(id);
afterExecute();
}
}, 150);
};
Jasmine.safeExecuteBeforeOrAfter = function(spec, func) {
try {
func.apply(spec);
} catch (e) {
var fail = {passed: false, message: func.typeName + '() fail: ' + Jasmine.util.formatException(e)};
spec.results.push(fail);
}
};
/*
* QueuedFunction is how ActionCollections' actions are implemented
*/
Jasmine.QueuedFunction = function(func, timeout, latchFunction, spec) {
this.func = func;
this.timeout = timeout;
this.latchFunction = latchFunction;
this.spec = spec;
this.totalTimeSpentWaitingForLatch = 0;
this.latchTimeoutIncrement = 100;
};
Jasmine.QueuedFunction.prototype.next = function() {
this.spec.finish(); // default value is to be done after one function
};
Jasmine.QueuedFunction.prototype.safeExecute = function() {
if (console) {
console.log('>> Jasmine Running ' + this.spec.suite.description + ' ' + this.spec.description + '...');
}
try {
this.func.apply(this.spec);
} catch (e) {
this.fail(e);
}
};
Jasmine.QueuedFunction.prototype.execute = function() {
var self = this;
var executeNow = function() {
self.safeExecute();
self.next();
};
var executeLater = function() {
setTimeout(executeNow, self.timeout);
};
var executeNowOrLater = function() {
var latchFunctionResult;
try {
latchFunctionResult = self.latchFunction.apply(self.spec);
} catch (e) {
self.fail(e);
self.next();
return;
}
if (latchFunctionResult) {
executeNow();
} else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.latchFunction.description || 'something to happen');
self.fail({ name: 'timeout', message: message });
self.next();
} else {
self.totalTimeSpentWaitingForLatch += self.latchTimeoutIncrement;
setTimeout(executeNowOrLater, self.latchTimeoutIncrement);
}
};
if (this.latchFunction !== undefined) {
executeNowOrLater();
} else if (this.timeout > 0) {
executeLater();
} else {
executeNow();
}
};
Jasmine.QueuedFunction.prototype.fail = function(e) {
this.spec.results.push({passed:false, message: Jasmine.util.formatException(e)});
};
/******************************************************************************
* Jasmine
******************************************************************************/
Jasmine.Env = function() {
this.currentSpec = null;
this.currentSuite = null;
this.currentRunner = null;
};
Jasmine.Env.prototype.execute = function() {
this.currentRunner.execute();
};
Jasmine.currentEnv_ = new Jasmine.Env();
/** @deprecated use Jasmine.getEnv() instead */
var jasmine = Jasmine.currentEnv_;
Jasmine.getEnv = function() {
return Jasmine.currentEnv_;
};
Jasmine.isArray_ = function(value) {
return value &&
typeof value === 'object' &&
typeof value.length === 'number' &&
typeof value.splice === 'function' &&
!(value.propertyIsEnumerable('length'));
};
Jasmine.arrayToString_ = function(array) {
var formatted_value = '';
for (var i = 0; i < array.length; i++) {
if (i > 0) {
formatted_value += ', ';
}
;
formatted_value += Jasmine.pp(array[i]);
}
return '[ ' + formatted_value + ' ]';
};
Jasmine.objectToString_ = function(obj) {
var formatted_value = '';
var first = true;
for (var property in obj) {
if (property == '__Jasmine_pp_has_traversed__') continue;
if (first) {
first = false;
} else {
formatted_value += ', ';
}
formatted_value += property;
formatted_value += ' : ';
formatted_value += Jasmine.pp(obj[property]);
}
return '{ ' + formatted_value + ' }';
};
Jasmine.ppNestLevel_ = 0;
Jasmine.pp = function(value) {
if (Jasmine.ppNestLevel_ > 40) {
// return '(Jasmine.pp nested too deeply!)';
throw new Error('Jasmine.pp nested too deeply!');
}
Jasmine.ppNestLevel_++;
try {
return Jasmine.pp_(value);
} finally {
Jasmine.ppNestLevel_--;
}
};
Jasmine.pp_ = function(value) {
if (value === undefined) {
return 'undefined';
}
if (value === null) {
return 'null';
}
if (value.navigator && value.frames && value.setTimeout) {
return '<window>';
}
if (value instanceof Jasmine.Any) return value.toString();
if (typeof value === 'string') {
return "'" + Jasmine.util.htmlEscape(value) + "'";
}
if (typeof value === 'function') {
return 'Function';
}
if (typeof value.nodeType === 'number') {
return 'HTMLNode';
}
if (value.__Jasmine_pp_has_traversed__) {
return '<circular reference: ' + (Jasmine.isArray_(value) ? 'Array' : 'Object') + '>';
}
if (Jasmine.isArray_(value) || typeof value == 'object') {
value.__Jasmine_pp_has_traversed__ = true;
var stringified = Jasmine.isArray_(value) ? Jasmine.arrayToString_(value) : Jasmine.objectToString_(value);
delete value.__Jasmine_pp_has_traversed__;
return stringified;
}
return Jasmine.util.htmlEscape(value.toString());
};
/*
* Jasmine.Matchers methods; add your own by extending Jasmine.Matchers.prototype - don't forget to write a test
*
*/
Jasmine.Matchers = function(actual, results) {
this.actual = actual;
this.passing_message = 'Passed.';
this.results = results || new Jasmine.NestedResults();
};
Jasmine.Matchers.prototype.report = function(result, failing_message) {
this.results.push({
passed: result,
message: result ? this.passing_message : failing_message
});
return result;
};
Jasmine.isDomNode = function(obj) {
return obj['nodeType'] > 0;
};
Jasmine.Any = function(expectedClass) {
this.expectedClass = expectedClass;
};
Jasmine.Any.prototype.matches = function(other) {
if (this.expectedClass == String) {
return typeof other == 'string' || other instanceof String;
}
if (this.expectedClass == Number) {
return typeof other == 'number' || other instanceof Number;
}
return other instanceof this.expectedClass;
};
Jasmine.Any.prototype.toString = function() {
return '<Jasmine.any(' + this.expectedClass + ')>';
};
Jasmine.any = function(clazz) {
return new Jasmine.Any(clazz);
};
Jasmine.Matchers.prototype.toEqual = function(expected) {
var mismatchKeys = [];
var mismatchValues = [];
var hasKey = function(obj, keyName) {
return obj!=null && obj[keyName] !== undefined;
};
var equal = function(a, b) {
if (a == undefined || a == null) {
return (a == undefined && b == undefined);
}
if (Jasmine.isDomNode(a) && Jasmine.isDomNode(b)) {
return a === b;
}
if (typeof a === "object" && typeof b === "object") {
for (var property in b) {
if (!hasKey(a, property) && hasKey(b, property)) {
mismatchKeys.push("expected has key '" + property + "', but missing from <b>actual</b>.");
}
}
for (property in a) {
if (!hasKey(b, property) && hasKey(a, property)) {
mismatchKeys.push("<b>expected</b> missing key '" + property + "', but present in actual.");
}
}
for (property in b) {
if (!equal(a[property], b[property])) {
mismatchValues.push("'" + property + "' was<br /><br />'" + (b[property] ? Jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "'<br /><br />in expected, but was<br /><br />'" + (a[property] ? Jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "'<br /><br />in actual.<br />");
}
}
return (mismatchKeys.length == 0 && mismatchValues.length == 0);
}
if (b instanceof Jasmine.Any) {
return b.matches(a);
}
// functions are considered equivalent if their bodies are equal // todo: remove this
if (typeof a === "function" && typeof b === "function") {
return a.toString() == b.toString();
}
//Straight check
return (a === b);
};
var formatMismatches = function(name, array) {
if (array.length == 0) return '';
var errorOutput = '<br /><br />Different ' + name + ':<br />';
for (var i = 0; i < array.length; i++) {
errorOutput += array[i] + '<br />';
}
return errorOutput;
};
return this.report(equal(this.actual, expected),
'Expected<br /><br />' + Jasmine.pp(expected)
+ '<br /><br />but got<br /><br />' + Jasmine.pp(this.actual)
+ '<br />'
+ formatMismatches('Keys', mismatchKeys)
+ formatMismatches('Values', mismatchValues));
};
/** @deprecated */
Jasmine.Matchers.prototype.should_equal = Jasmine.Matchers.prototype.toEqual;
Jasmine.Matchers.prototype.toNotEqual = function(expected) {
return this.report((this.actual !== expected),
'Expected ' + Jasmine.pp(expected) + ' to not equal ' + Jasmine.pp(this.actual) + ', but it does.');
};
/** @deprecated */
Jasmine.Matchers.prototype.should_not_equal = Jasmine.Matchers.prototype.toNotEqual;
Jasmine.Matchers.prototype.toMatch = function(reg_exp) {
return this.report((new RegExp(reg_exp).test(this.actual)),
'Expected ' + this.actual + ' to match ' + reg_exp + '.');
};
/** @deprecated */
Jasmine.Matchers.prototype.should_match = Jasmine.Matchers.prototype.toMatch;
Jasmine.Matchers.prototype.toNotMatch = function(reg_exp) {
return this.report((!new RegExp(reg_exp).test(this.actual)),
'Expected ' + this.actual + ' to not match ' + reg_exp + '.');
};
/** @deprecated */
Jasmine.Matchers.prototype.should_not_match = Jasmine.Matchers.prototype.toNotMatch;
Jasmine.Matchers.prototype.toBeDefined = function() {
return this.report((this.actual !== undefined),
'Expected a value to be defined but it was undefined.');
};
/** @deprecated */
Jasmine.Matchers.prototype.should_be_defined = Jasmine.Matchers.prototype.toBeDefined;
Jasmine.Matchers.prototype.toBeNull = function() {
return this.report((this.actual === null),
'Expected a value to be null but it was not.');
};
/** @deprecated */
Jasmine.Matchers.prototype.should_be_null = Jasmine.Matchers.prototype.toBeNull;
Jasmine.Matchers.prototype.toBeTruthy = function() {
return this.report((this.actual),
'Expected a value to be truthy but it was not.');
};
/** @deprecated */
Jasmine.Matchers.prototype.should_be_truthy = Jasmine.Matchers.prototype.toBeTruthy;
Jasmine.Matchers.prototype.toBeFalsy = function() {
return this.report((!this.actual),
'Expected a value to be falsy but it was not.');
};
/** @deprecated */
Jasmine.Matchers.prototype.should_be_falsy = Jasmine.Matchers.prototype.toBeFalsy;
Jasmine.Matchers.prototype.wasCalled = function() {
if (!this.actual.isSpy) {
return this.report(false, 'Expected value to be a spy, but it was not.');
}
return this.report((this.actual.wasCalled),
'Expected spy to have been called, but it was not.');
};
/** @deprecated */
Jasmine.Matchers.prototype.was_called = Jasmine.Matchers.prototype.wasCalled;
Jasmine.Matchers.prototype.wasNotCalled = function() {
if (!this.actual.isSpy) {
return this.report(false, 'Expected value to be a spy, but it was not.');
}
return this.report((!this.actual.wasCalled),
'Expected spy to not have been called, but it was.');
};
/** @deprecated */
Jasmine.Matchers.prototype.was_not_called = Jasmine.Matchers.prototype.wasNotCalled;
Jasmine.Matchers.prototype.wasCalledWith = function() {
if (!this.wasCalled()) return false;
var argMatcher = new Jasmine.Matchers(this.actual.mostRecentCall.args, this.results);
return argMatcher.toEqual(Jasmine.util.argsToArray(arguments));
};
/** @deprecated */
Jasmine.Matchers.prototype.was_called = Jasmine.Matchers.prototype.wasCalled;
Jasmine.Matchers.prototype.toContain = function(item) {
return this.report((this.actual.indexOf(item) >= 0),
'Expected ' + Jasmine.pp(this.actual) + ' to contain ' + Jasmine.pp(item) + ', but it does not.');
};
Jasmine.Matchers.prototype.toNotContain = function(item) {
return this.report((this.actual.indexOf(item) < 0),
'Expected ' + Jasmine.pp(this.actual) + ' not to contain ' + Jasmine.pp(item) + ', but it does.');
};
Jasmine.createSpy = function() {
var spyObj = function() {
spyObj.wasCalled = true;
spyObj.callCount++;
var args = Jasmine.util.argsToArray(arguments);
spyObj.mostRecentCall = {
object: this,
args: args
};
spyObj.argsForCall.push(args);
return spyObj.plan.apply(this, arguments);
};
spyObj.isSpy = true;
spyObj.plan = function() {
};
spyObj.andCallThrough = function() {
spyObj.plan = spyObj.originalValue;
return spyObj;
};
spyObj.andReturn = function(value) {
spyObj.plan = function() {
return value;
};
return spyObj;
};
spyObj.andThrow = function(exceptionMsg) {
spyObj.plan = function() {
throw exceptionMsg;
};
return spyObj;
};
spyObj.andCallFake = function(fakeFunc) {
spyObj.plan = fakeFunc;
return spyObj;
};
spyObj.reset = function() {
spyObj.wasCalled = false;
spyObj.callCount = 0;
spyObj.argsForCall = [];
spyObj.mostRecentCall = {};
};
spyObj.reset();
return spyObj;
};
Jasmine.spyOn = function(obj, methodName) {
var spec = Jasmine.getEnv().currentSpec;
spec.after(function() {
spec.removeAllSpies();
});
if (obj == undefined) {
throw "spyOn could not find an object to spy upon";
}
if (obj[methodName] === undefined) {
throw methodName + '() method does not exist';
}
if (obj[methodName].isSpy) {
throw new Error(methodName + ' has already been spied upon');
}
var spyObj = Jasmine.createSpy();
spec.spies_.push(spyObj);
spyObj.baseObj = obj;
spyObj.methodName = methodName;
spyObj.originalValue = obj[methodName];
obj[methodName] = spyObj;
return spyObj;
};
var spyOn = Jasmine.spyOn;
/*
* Jasmine spec constructor
*/
Jasmine.Spec = function(description) {
this.suite = null;
this.description = description;
this.queue = [];
this.currentTimeout = 0;
this.currentLatchFunction = undefined;
this.finished = false;
this.afterCallbacks = [];
this.spies_ = [];
this.results = new Jasmine.NestedResults();
};
Jasmine.Spec.prototype.freezeSuite = function(suite) {
this.suite = suite;
};
/** @deprecated */
Jasmine.Spec.prototype.expects_that = function(actual) {
return new Jasmine.Matchers(actual, this.results);
};
Jasmine.Spec.prototype.waits = function(timeout) {
this.currentTimeout = timeout;
this.currentLatchFunction = undefined;
return this;
};
Jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, message) {
this.currentTimeout = timeout;
this.currentLatchFunction = latchFunction;
this.currentLatchFunction.description = message;
return this;
};
Jasmine.Spec.prototype.resetTimeout = function() {
this.currentTimeout = 0;
this.currentLatchFunction = undefined;
};
Jasmine.Spec.prototype.finishCallback = function() {
if (Jasmine.getEnv().reporter) {
Jasmine.getEnv().reporter.reportSpecResults(this.results);
}
};
Jasmine.Spec.prototype.finish = function() {
if (this.suite.afterEach) {
Jasmine.safeExecuteBeforeOrAfter(this, this.suite.afterEach);
}
this.finishCallback();
this.finished = true;
};
Jasmine.Spec.prototype.after = function(doAfter) {
this.afterCallbacks.push(doAfter);
};
Jasmine.Spec.prototype.execute = function() {
Jasmine.getEnv().currentSpec = this;
if (this.suite.beforeEach) {
Jasmine.safeExecuteBeforeOrAfter(this, this.suite.beforeEach);
}
if (this.queue[0]) {
this.queue[0].execute();
} else {
this.finish();
}
};
Jasmine.Spec.prototype.explodes = function() {
throw 'explodes function should not have been called';
};
Jasmine.Spec.prototype.spyOn = Jasmine.spyOn;
Jasmine.Spec.prototype.removeAllSpies = function() {
for (var i = 0; i < this.spies_.length; i++) {
var spy = this.spies_[i];
spy.baseObj[spy.methodName] = spy.originalValue;
}
this.spies_ = [];
};
var it = function(description, func) {
var that = new Jasmine.Spec(description);
var addToQueue = function(func) {
var currentFunction = new Jasmine.QueuedFunction(func, that.currentTimeout, that.currentLatchFunction, that);
that.queue.push(currentFunction);
if (that.queue.length > 1) {
var previousFunction = that.queue[that.queue.length - 2];
previousFunction.next = function() {
currentFunction.execute();
};
}
that.resetTimeout();
return that;
};
that.expectationResults = that.results.results;
that.runs = addToQueue;
that.freezeSuite(Jasmine.getEnv().currentSuite);
Jasmine.getEnv().currentSuite.specs.push(that);
Jasmine.getEnv().currentSpec = that;
if (func) {
addToQueue(func);
}
that.results.description = description;
return that;
};
//this mirrors the spec syntax so you can define a spec description that will not run.
var xit = function() {
return {runs: function() {
} };
};
var expect = function() {
return Jasmine.getEnv().currentSpec.expects_that.apply(Jasmine.getEnv().currentSpec, arguments);
};
var runs = function(func) {
Jasmine.getEnv().currentSpec.runs(func);
};
var waits = function(timeout) {
Jasmine.getEnv().currentSpec.waits(timeout);
};
var waitsFor = function(timeout, latchFunction, message) {
Jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message);
};
var beforeEach = function(beforeEach) {
beforeEach.typeName = 'beforeEach';
Jasmine.getEnv().currentSuite.beforeEach = beforeEach;
};
var afterEach = function(afterEach) {
afterEach.typeName = 'afterEach';
Jasmine.getEnv().currentSuite.afterEach = afterEach;
};
Jasmine.Description = function(description, specDefinitions) {
Jasmine.ActionCollection.call(this);
this.description = description;
this.specs = this.actions;
};
Jasmine.util.inherit(Jasmine.Description, Jasmine.ActionCollection);
var describe = function(description, spec_definitions) {
var that = new Jasmine.Description(description, spec_definitions);
Jasmine.getEnv().currentSuite = that;
Jasmine.getEnv().currentRunner.suites.push(that);
spec_definitions();
that.results.description = description;
that.specResults = that.results.results;
that.finishCallback = function() {
if (Jasmine.getEnv().reporter) {
Jasmine.getEnv().reporter.reportSuiteResults(that.results);
}
};
return that;
};
var xdescribe = function() {
return {execute: function() {
}};
};
Jasmine.Runner = function() {
Jasmine.ActionCollection.call(this);
this.suites = this.actions;
this.results.description = 'All Jasmine Suites';
};
Jasmine.util.inherit(Jasmine.Runner, Jasmine.ActionCollection);
var Runner = function() {
var that = new Jasmine.Runner();
that.finishCallback = function() {
if (Jasmine.getEnv().reporter) {
Jasmine.getEnv().reporter.reportRunnerResults(that.results);
}
};
that.suiteResults = that.results.results;
Jasmine.getEnv().currentRunner = that;
return that;
};
Jasmine.getEnv().currentRunner = Runner();
/* JasmineReporters.reporter
* Base object that will get called whenever a Spec, Suite, or Runner is done. It is up to
* descendants of this object to do something with the results (see json_reporter.js)
*/
Jasmine.Reporters = {};
Jasmine.Reporters.reporter = function(callbacks) {
var that = {
callbacks: callbacks || {},
doCallback: function(callback, results) {
if (callback) {
callback(results);
}
},
reportRunnerResults: function(results) {
that.doCallback(that.callbacks.runnerCallback, results);
},
reportSuiteResults: function(results) {
that.doCallback(that.callbacks.suiteCallback, results);
},
reportSpecResults: function(results) {
that.doCallback(that.callbacks.specCallback, results);
}
};
return that;
};
Jasmine.util.formatException = function(e) {
var lineNumber;
if (e.line) {
lineNumber = e.line;
}
else if (e.lineNumber) {
lineNumber = e.lineNumber;
}
var file;
if (e.sourceURL) {
file = e.sourceURL;
}
else if (e.fileName) {
file = e.fileName;
}
var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString();
if (file && lineNumber) {
message += ' in ' + file + ' (line ' + lineNumber + ')';
}
return message;
};
Jasmine.util.htmlEscape = function(str) {
if (!str) return str;
return str.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>');
};
Jasmine.util.argsToArray = function(args) {
var arrayOfArgs = [];
for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
return arrayOfArgs;
};