1
describe("jasmine spec running", function () {
5
beforeEach(function() {
6
env = new jasmine.Env();
7
env.updateInterval = 0;
9
fakeTimer = new jasmine.FakeTimer();
10
env.setTimeout = fakeTimer.setTimeout;
11
env.clearTimeout = fakeTimer.clearTimeout;
12
env.setInterval = fakeTimer.setInterval;
13
env.clearInterval = fakeTimer.clearInterval;
16
it('should assign spec ids sequentially', function() {
17
var it0, it1, it2, it3, it4;
18
env.describe('test suite', function() {
19
it0 = env.it('spec 0', function() {
21
it1 = env.it('spec 1', function() {
23
it2 = env.xit('spec 2', function() {
25
it3 = env.it('spec 3', function() {
28
env.describe('test suite 2', function() {
29
it4 = env.it('spec 4', function() {
33
expect(it0.id).toEqual(0);
34
expect(it1.id).toEqual(1);
35
expect(it2.id).toEqual(2);
36
expect(it3.id).toEqual(3);
37
expect(it4.id).toEqual(4);
40
it("should build up some objects with results we can inspect", function() {
42
var specWithNoBody, specWithExpectation, specWithFailingExpectations, specWithMultipleExpectations;
44
var suite = env.describe('default current suite', function() {
45
specWithNoBody = env.it('new spec');
47
specWithExpectation = env.it('spec with an expectation').runs(function () {
49
this.expect(foo).toEqual('bar');
52
specWithFailingExpectations = env.it('spec with failing expectation').runs(function () {
54
this.expect(foo).toEqual('baz');
57
specWithMultipleExpectations = env.it('spec with multiple expectations').runs(function () {
61
this.expect(foo).toEqual('bar');
62
this.expect(baz).toEqual('quux');
68
expect(specWithNoBody.description).toEqual('new spec');
70
expect(specWithExpectation.results().getItems().length).toEqual(1); // "Results aren't there after a spec was executed"
71
expect(specWithExpectation.results().getItems()[0].passed()).toEqual(true); // "Results has a result, but it's true"
72
expect(specWithExpectation.results().description).toEqual('spec with an expectation'); // "Spec's results did not get the spec's description"
74
expect(specWithFailingExpectations.results().getItems()[0].passed()).toEqual(false); // "Expectation that failed, passed"
76
expect(specWithMultipleExpectations.results().getItems().length).toEqual(2); // "Spec doesn't support multiple expectations"
79
it("should work without a runs block", function() {
81
env.describe('default current suite', function() {
82
another_spec = env.it('spec with an expectation', function () {
84
this.expect(foo).toEqual('bar');
85
this.expect(foo).toEqual('baz');
89
another_spec.execute();
90
another_spec.done = true;
92
expect(another_spec.results().getItems().length).toEqual(2);
93
expect(another_spec.results().getItems()[0].passed()).toEqual(true); // "In a spec without a run block, expected first expectation result to be true but was false"
94
expect(another_spec.results().getItems()[1].passed()).toEqual(false); // "In a spec without a run block, expected second expectation result to be false but was true";
95
expect(another_spec.results().description).toEqual('spec with an expectation'); // "In a spec without a run block, results did not include the spec's description";
98
it('should queue waits and runs that it encounters while executing specs', function() {
99
var specWithRunsAndWaits;
101
env.describe('test async spec', function() {
102
specWithRunsAndWaits = env.it('spec w/ queued statments', function () {
103
this.runs(function () {
107
this.runs(function () {
111
this.runs(function () {
117
expect(foo).toEqual(0);
118
specWithRunsAndWaits.execute();
120
expect(foo).toEqual(1);
122
expect(foo).toEqual(2);
124
expect(foo).toEqual(3);
127
it("should run asynchronous tests", function () {
131
env.describe('test async spec', function() {
132
a_spec = env.it('spec w/ queued statments', function () {
133
this.runs(function () {
136
this.runs(function () {
137
this.expect(foo).toEqual(1);
144
expect(a_spec.results().getItems().length).toEqual(1); // 'No call to waits(): Spec queue did not run all functions';
145
expect(a_spec.results().getItems()[0].passed()).toEqual(true); // 'No call to waits(): Queued expectation failed';
148
env.describe('test async spec', function() {
149
a_spec = env.it('spec w/ queued statments', function () {
150
this.runs(function () {
151
fakeTimer.setTimeout(function() {
156
this.runs(function() {
157
this.expect(foo).toEqual(1);
164
expect(a_spec.results().getItems().length).toEqual(0);
167
expect(a_spec.results().getItems().length).toEqual(0);
170
expect(a_spec.results().getItems().length).toEqual(1); // 'Calling waits(): Spec queue did not run all functions';
172
expect(a_spec.results().getItems()[0].passed()).toEqual(true); // 'Calling waits(): Queued expectation failed';
176
env.describe('test async spec', function() {
177
another_spec = env.it('spec w/ queued statments', function () {
178
this.runs(function () {
179
fakeTimer.setTimeout(function() {
185
this.runs(function () {
186
fakeTimer.setTimeout(function() {
191
this.runs(function () {
192
this.expect(bar).toEqual(2);
198
another_spec.execute();
200
fakeTimer.tick(1000);
202
expect(another_spec.results().getItems().length).toEqual(1);
203
expect(another_spec.results().getItems()[0].passed()).toEqual(true);
206
var yet_another_spec;
207
env.describe('test async spec', function() {
208
yet_another_spec = env.it('spec w/ async fail', function () {
209
this.runs(function () {
210
fakeTimer.setTimeout(function() {
215
this.runs(function() {
216
this.expect(baz).toEqual(1);
222
yet_another_spec.execute();
223
//tick twice so that second runs gets eval'd first: mockClock bug?
228
expect(yet_another_spec.results().getItems().length).toEqual(1);
229
expect(yet_another_spec.results().getItems()[0].passed()).toEqual(false);
232
it("testAsyncSpecsWithMockSuite", function () {
235
env.describe('test async spec', function() {
236
another_spec = env.it('spec w/ queued statments', function () {
237
this.runs(function () {
238
fakeTimer.setTimeout(function() {
243
this.runs(function () {
244
fakeTimer.setTimeout(function() {
249
this.runs(function() {
250
this.expect(bar).toEqual(2);
255
another_spec.execute();
256
fakeTimer.tick(2000);
257
expect(another_spec.results().getItems().length).toEqual(1);
258
expect(another_spec.results().getItems()[0].passed()).toEqual(true);
261
describe("waitsFor", function() {
262
var latchFunction = function() {
267
function makeWaitsForSpec() {
268
var args = jasmine.util.argsToArray(arguments);
269
env.describe('suite', function() {
270
spec = env.it('spec', function() {
271
this.waitsFor.apply(this, args);
277
it("should accept args (latchFunction, timeoutMessage, timeout)", function() {
278
makeWaitsForSpec(latchFunction, "message", 123);
279
var block = spec.queue.blocks[1];
280
expect(block.latchFunction).toBe(latchFunction);
281
expect(block.timeout).toEqual(123);
282
expect(block.message).toEqual('message');
285
it("should accept args (latchFunction, timeout)", function() {
286
makeWaitsForSpec(latchFunction, 123);
287
var block = spec.queue.blocks[1];
288
expect(block.latchFunction).toBe(latchFunction);
289
expect(block.timeout).toEqual(123);
290
expect(block.message).toEqual(null);
293
it("should accept args (latchFunction, timeoutMessage)", function() {
294
env.defaultTimeoutInterval = 4321;
295
makeWaitsForSpec(latchFunction, "message");
296
var block = spec.queue.blocks[1];
297
expect(block.latchFunction).toBe(latchFunction);
298
expect(block.timeout).toEqual(4321);
299
expect(block.message).toEqual('message');
302
it("should accept args (latchFunction)", function() {
303
env.defaultTimeoutInterval = 4321;
304
makeWaitsForSpec(latchFunction);
305
var block = spec.queue.blocks[1];
306
expect(block.latchFunction).toBe(latchFunction);
307
expect(block.timeout).toEqual(4321);
308
expect(block.message).toEqual(null);
311
it("should accept deprecated args order (timeout, latchFunction, timeoutMessage)", function() {
312
makeWaitsForSpec(123, latchFunction, "message");
313
var block = spec.queue.blocks[1];
314
expect(block.latchFunction).toBe(latchFunction);
315
expect(block.timeout).toEqual(123);
316
expect(block.message).toEqual('message');
319
it("testWaitsFor", function() {
320
var doneWaiting = false;
321
var runsBlockExecuted = false;
324
env.describe('foo', function() {
325
spec = env.it('has a waits for', function() {
326
this.runs(function() {
329
this.waitsFor(500, function() {
333
this.runs(function() {
334
runsBlockExecuted = true;
340
expect(runsBlockExecuted).toEqual(false); //, 'should not have executed runs block yet');
344
expect(runsBlockExecuted).toEqual(true); //, 'should have executed runs block');
347
it("fails with message", function() {
349
env.describe('foo', function() {
350
spec = env.it('has a waits for', function() {
351
this.runs(function() {
354
this.waitsFor(500, function() {
355
return false; // force a timeout
356
}, 'my awesome condition');
358
this.runs(function() {
364
fakeTimer.tick(1000);
365
expect(spec.results().getItems()[0].message).toEqual('timeout: timed out after 500 msec waiting for my awesome condition');
368
it("fails and skips the rest of the spec if timeout is reached and the latch function hasn't returned true", function() {
369
var runsBlockExecuted = false;
370
var subsequentSpecRan = false;
372
var timeoutSpec, subsequentSpec;
373
var suite = env.describe('foo', function() {
374
timeoutSpec = env.it('has a waits for', function() {
375
this.runs(function() {
378
this.waitsFor(500, function() {
382
this.runs(function() {
383
runsBlockExecuted = true;
387
subsequentSpec = env.it('then carries on to the next test', function() {
388
subsequentSpecRan = true;
393
expect(runsBlockExecuted).toEqual(false);
395
expect(runsBlockExecuted).toEqual(false);
397
expect(runsBlockExecuted).toEqual(false);
398
expect(timeoutSpec.results().getItems()[0].message).toEqual('timeout: timed out after 500 msec waiting for something to happen');
399
expect(subsequentSpecRan).toEqual(true);
402
it("runs afterEach after timing out", function() {
403
var afterEach = jasmine.createSpy('afterEach');
405
env.describe('foo', function () {
406
env.afterEach(afterEach);
408
env.it('waitsFor', function () {
409
this.waitsFor(100, function() {
416
expect(afterEach).toHaveBeenCalled();
419
it("runs single-spec after functions after timing out", function() {
420
var after = jasmine.createSpy('after');
422
env.describe('foo', function () {
423
env.it('waitsFor', function () {
425
this.waitsFor(100, function() {
432
expect(after).toHaveBeenCalled();
435
describe('with consecutive calls', function () {
437
beforeEach(function () {
441
it('exits immediately (does not stack) if the latchFunction times out', function () {
442
var reachedFirstWaitsFor = false;
443
var reachedSecondWaitsFor = false;
444
env.describe('suite that waits', function () {
445
env.it('should stack timeouts', function() {
446
this.waitsFor(500, function () {
447
reachedFirstWaitsFor = true;
450
this.waitsFor(500, function () {
451
reachedSecondWaitsFor = true;
453
this.runs(function () {
459
expect(reachedFirstWaitsFor).toEqual(false);
462
expect(reachedFirstWaitsFor).toEqual(true);
463
expect(foo).toEqual(0);
464
expect(reachedSecondWaitsFor).toEqual(false);
466
expect(reachedSecondWaitsFor).toEqual(false);
467
expect(foo).toEqual(0);
469
expect(reachedSecondWaitsFor).toEqual(false);
470
expect(foo).toEqual(0);
473
it('stacks latchFunctions', function () {
474
var firstWaitsResult = false;
475
var secondWaitsResult = false;
476
var waitsSuite = env.describe('suite that waits', function () {
477
env.it('spec with waitsFors', function() {
478
this.waitsFor(600, function () {
479
fakeTimer.setTimeout(function () {
480
firstWaitsResult = true;
482
return firstWaitsResult;
484
this.waitsFor(600, function () {
485
fakeTimer.setTimeout(function () {
486
secondWaitsResult = true;
488
return secondWaitsResult;
490
this.runs(function () {
496
expect(firstWaitsResult).toEqual(false);
497
expect(secondWaitsResult).toEqual(false);
498
waitsSuite.execute();
500
expect(firstWaitsResult).toEqual(false);
501
expect(secondWaitsResult).toEqual(false);
502
expect(foo).toEqual(0);
506
expect(firstWaitsResult).toEqual(true);
507
expect(secondWaitsResult).toEqual(false);
508
expect(foo).toEqual(0);
512
expect(firstWaitsResult).toEqual(true);
513
expect(secondWaitsResult).toEqual(true);
514
expect(foo).toEqual(1);
520
it("testSpecAfter", function() {
523
var suite = env.describe("has after", function() {
524
spec = env.it('spec with after', function() {
525
this.runs(function() {
530
spec.after(function() {
533
spec.after(function() {
539
expect(log).toEqual("specafter2after1");
542
describe('test suite declaration', function() {
544
var dummyFunction = function() {
547
it('should give the suite a description', function() {
548
suite = env.describe('one suite description', dummyFunction);
549
expect(suite.description).toEqual('one suite description');
552
it('should enqueue functions for multipart tests and support waits, and run any ready runs() blocks', function() {
556
suite = env.describe('one suite description', function () {
557
env.it('should be a test with queuedFunctions', function() {
558
this.runs(function() {
562
this.runs(function() {
570
expect(foo).toEqual(1);
571
expect(bar).toEqual(0);
574
expect(bar).toEqual(1);
579
it("testBeforeAndAfterCallbacks", function () {
580
var suiteWithBefore = env.describe('one suite with a before', function () {
582
this.beforeEach(function () {
586
env.it('should be a spec', function () {
587
this.runs(function() {
589
this.expect(this.foo).toEqual(2);
593
env.it('should be another spec', function () {
594
this.runs(function() {
596
this.expect(this.foo).toEqual(2);
601
suiteWithBefore.execute();
603
var suite = suiteWithBefore;
605
expect(suite.results().getItems()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2");
606
expect(suite.results().getItems()[1].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the second spec's this.foo should have been 2");
610
var suiteWithAfter = env.describe('one suite with an after_each', function () {
612
env.it('should be a spec with an after_each', function () {
613
this.expect(foo).toEqual(1);
615
this.expect(foo).toEqual(2);
618
env.it('should be another spec with an after_each', function () {
619
this.expect(foo).toEqual(0);
621
this.expect(foo).toEqual(1);
624
this.afterEach(function () {
629
suiteWithAfter.execute();
631
suite = suiteWithAfter;
632
expect(suite.afterEach.length).toEqual(1);
633
expect(suite.results().getItems()[0].passed()).toEqual(true);
634
expect(suite.results().getItems()[1].passed()).toEqual(true);
635
expect(foo).toEqual(0);
639
it('#waits should allow consecutive waits calls', function () {
641
var waitsSuite = env.describe('suite that waits', function () {
642
env.it('should wait', function() {
645
this.runs(function () {
651
waitsSuite.execute();
652
expect(foo).toEqual(0);
654
expect(foo).toEqual(0);
657
expect(foo).toEqual(1);
660
it('nested suites', function () {
666
var nested = env.describe('suite', function () {
667
env.describe('nested', function () {
668
env.it('should run nested suites', function () {
671
env.it('should run nested suites', function () {
676
env.describe('nested 2', function () {
677
env.it('should run suites following nested suites', function () {
682
env.it('should run tests following nested suites', function () {
687
expect(foo).toEqual(0);
688
expect(bar).toEqual(0);
689
expect(baz).toEqual(0);
690
expect(quux).toEqual(0);
693
expect(foo).toEqual(1);
694
expect(bar).toEqual(1);
695
expect(baz).toEqual(1);
696
expect(quux).toEqual(1);
699
it("#beforeEach should be able to eval runs and waits blocks", function () {
702
var suiteWithBefore = env.describe('one suite with a before', function () {
703
this.beforeEach(function () {
704
this.runs(function () {
708
this.runs(function () {
714
env.it('should be a spec', function () {
721
expect(foo).toEqual(0);
722
expect(bar).toEqual(0);
723
suiteWithBefore.execute();
725
expect(bar).toEqual(0);
726
expect(foo).toEqual(1);
729
expect(bar).toEqual(0);
730
expect(foo).toEqual(2);
732
expect(bar).toEqual(1);
733
expect(foo).toEqual(3);
736
it("#afterEach should be able to eval runs and waits blocks", function () {
738
var firstSpecHasRun = false;
739
var secondSpecHasRun = false;
740
var suiteWithAfter = env.describe('one suite with a before', function () {
741
this.afterEach(function () {
743
this.runs(function () {
749
env.it('should be the first spec', function () {
750
firstSpecHasRun = true;
753
env.it('should be a spec', function () {
754
secondSpecHasRun = true;
760
expect(firstSpecHasRun).toEqual(false);
761
expect(secondSpecHasRun).toEqual(false);
762
expect(foo).toEqual(0);
764
suiteWithAfter.execute();
767
expect(firstSpecHasRun).toEqual(true);
768
expect(secondSpecHasRun).toEqual(false);
769
expect(foo).toEqual(0);
773
expect(foo).toEqual(1);
774
expect(secondSpecHasRun).toEqual(false);
777
expect(foo).toEqual(2);
778
expect(secondSpecHasRun).toEqual(true);
782
it("Spec#after should be able to eval runs and waits blocks", function () {
783
var runsBeforeAfter = false;
784
var firstSpecHasRun = false;
785
var secondSpecHasRun = false;
786
var afterHasRun = false;
787
var suiteWithAfter = env.describe('one suite with a before', function () {
789
env.it('should be the first spec', function () {
790
firstSpecHasRun = true;
791
this.after(function () {
793
this.runs(function () {
799
this.runs(function () {
800
runsBeforeAfter = true;
804
env.it('should be a spec', function () {
805
secondSpecHasRun = true;
810
expect(firstSpecHasRun).toEqual(false);
811
expect(runsBeforeAfter).toEqual(false);
812
expect(afterHasRun).toEqual(false);
813
expect(secondSpecHasRun).toEqual(false);
815
suiteWithAfter.execute();
817
expect(firstSpecHasRun).toEqual(true);
818
expect(runsBeforeAfter).toEqual(false);
819
expect(afterHasRun).toEqual(false);
820
expect(secondSpecHasRun).toEqual(false);
824
expect(firstSpecHasRun).toEqual(true);
825
expect(runsBeforeAfter).toEqual(true);
826
expect(afterHasRun).toEqual(false);
827
expect(secondSpecHasRun).toEqual(false);
831
expect(firstSpecHasRun).toEqual(true);
832
expect(runsBeforeAfter).toEqual(true);
833
expect(afterHasRun).toEqual(true);
834
expect(secondSpecHasRun).toEqual(false);
838
expect(firstSpecHasRun).toEqual(true);
839
expect(runsBeforeAfter).toEqual(true);
840
expect(afterHasRun).toEqual(true);
841
expect(secondSpecHasRun).toEqual(true);
844
it("handles waits", function () {
845
var firstSpecHasRun = false;
846
var secondSpecHasRun = false;
847
var suiteWithAfter = env.describe('one suite with a before', function () {
849
env.it('should be the first spec', function () {
851
this.runs(function () {
852
firstSpecHasRun = true;
856
env.it('should be a spec', function () {
857
secondSpecHasRun = true;
862
expect(firstSpecHasRun).toEqual(false);
863
expect(secondSpecHasRun).toEqual(false);
865
suiteWithAfter.execute();
867
expect(firstSpecHasRun).toEqual(false);
868
expect(secondSpecHasRun).toEqual(false);
872
expect(firstSpecHasRun).toEqual(true);
873
expect(secondSpecHasRun).toEqual(true);
876
it("testBeforeExecutesSafely", function() {
878
var suite = env.describe('before fails on first test, passes on second', function() {
880
this.beforeEach(function() {
883
throw "before failure";
886
env.it("first should not run because before fails", function() {
887
this.runs(function() {
889
this.expect(true).toEqual(true);
892
env.it("second should run and pass because before passes", function() {
893
this.runs(function() {
895
this.expect(true).toEqual(true);
902
expect(report).toEqual("firstsecond");
903
var suiteResults = suite.results();
904
expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false);
905
expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true);
908
it("testAfterExecutesSafely", function() {
910
var suite = env.describe('after fails on first test, then passes', function() {
912
this.afterEach(function() {
915
throw "after failure";
918
env.it("first should run, expectation passes, but spec fails because after fails", function() {
919
this.runs(function() {
921
this.expect(true).toEqual(true);
924
env.it("second should run and pass because after passes", function() {
925
this.runs(function() {
927
this.expect(true).toEqual(true);
930
env.it("third should run and pass because after passes", function() {
931
this.runs(function() {
933
this.expect(true).toEqual(true);
940
expect(report).toEqual("firstsecondthird"); // "all tests should run");
941
//After each errors should not go in spec results because it confuses the count.
942
var suiteResults = suite.results();
943
expect(suiteResults.getItems().length).toEqual(3, 'testAfterExecutesSafely should have results for three specs');
945
expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st spec should pass");
946
expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 2nd spec should pass");
947
expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd spec should pass");
949
expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st result for 1st suite spec should pass");
950
expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(false, "testAfterExecutesSafely 2nd result for 1st suite spec should fail because afterEach failed");
951
expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 2nd suite spec should pass");
952
expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd suite spec should pass");
955
it("should permit nested describes", function() {
958
env.beforeEach(function () {
959
actions.push('runner beforeEach');
962
env.afterEach(function () {
963
actions.push('runner afterEach');
966
env.describe('Something', function() {
967
env.beforeEach(function() {
968
actions.push('outer beforeEach');
971
env.afterEach(function() {
972
actions.push('outer afterEach');
975
env.it('does it 1', function() {
976
actions.push('outer it 1');
979
env.describe('Inner 1', function() {
980
env.beforeEach(function() {
981
actions.push('inner 1 beforeEach');
984
env.afterEach(function() {
985
actions.push('inner 1 afterEach');
988
env.it('does it 2', function() {
989
actions.push('inner 1 it');
993
env.it('does it 3', function() {
994
actions.push('outer it 2');
997
env.describe('Inner 2', function() {
998
env.beforeEach(function() {
999
actions.push('inner 2 beforeEach');
1002
env.afterEach(function() {
1003
actions.push('inner 2 afterEach');
1006
env.it('does it 2', function() {
1007
actions.push('inner 2 it');
1016
"runner beforeEach",
1022
"runner beforeEach",
1024
"inner 1 beforeEach",
1026
"inner 1 afterEach",
1030
"runner beforeEach",
1036
"runner beforeEach",
1038
"inner 2 beforeEach",
1040
"inner 2 afterEach",
1044
expect(actions).toEqual(expected);
1047
it("should run multiple befores and afters in the order they are declared", function() {
1050
env.beforeEach(function () {
1051
actions.push('runner beforeEach1');
1054
env.afterEach(function () {
1055
actions.push('runner afterEach1');
1058
env.beforeEach(function () {
1059
actions.push('runner beforeEach2');
1062
env.afterEach(function () {
1063
actions.push('runner afterEach2');
1066
env.describe('Something', function() {
1067
env.beforeEach(function() {
1068
actions.push('beforeEach1');
1071
env.afterEach(function() {
1072
actions.push('afterEach1');
1075
env.beforeEach(function() {
1076
actions.push('beforeEach2');
1079
env.afterEach(function() {
1080
actions.push('afterEach2');
1083
env.it('does it 1', function() {
1084
actions.push('outer it 1');
1091
"runner beforeEach1",
1092
"runner beforeEach2",
1098
"runner afterEach2",
1101
expect(actions).toEqual(expected);
1104
it("builds up nested names", function() {
1106
env.describe('Test Subject', function() {
1107
env.describe('when under circumstance A', function() {
1108
env.describe('and circumstance B', function() {
1109
nestedSpec = env.it('behaves thusly', function() {
1115
expect(nestedSpec.getFullName()).toEqual('Test Subject when under circumstance A and circumstance B behaves thusly.'); //, "Spec.fullName was incorrect: " + nestedSpec.getFullName());
1118
it("should skip empty suites", function () {
1119
env.describe('NonEmptySuite1', function() {
1120
env.it('should pass', function() {
1121
this.expect(true).toEqual(true);
1123
env.describe('NestedEmptySuite', function() {
1125
env.it('should pass', function() {
1126
this.expect(true).toEqual(true);
1130
env.describe('EmptySuite', function() {
1133
env.describe('NonEmptySuite2', function() {
1134
env.it('should pass', function() {
1135
this.expect(true).toEqual(true);
1141
var runnerResults = env.currentRunner_.results();
1142
expect(runnerResults.totalCount).toEqual(3);
1143
expect(runnerResults.passedCount).toEqual(3);
1144
expect(runnerResults.failedCount).toEqual(0);
1147
it("should bind 'this' to the running spec within the spec body", function() {
1149
var suite = env.describe('one suite description', function () {
1150
env.it('should be a test with queuedFunctions', function() {
1151
spec = this.runs(function() {
1156
this.runs(function() {
1158
fakeTimer.setTimeout(function() {
1163
this.runs(function() {
1164
this.expect(this.foo).toEqual(2);
1169
this.runs(function() {
1170
this.expect(this.foo).toEqual(2);
1177
fakeTimer.tick(600);
1178
expect(spec.foo).toEqual(2);
1179
var suiteResults = suite.results();
1180
expect(suiteResults.getItems()[0].getItems().length).toEqual(2);
1181
expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false);
1182
expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(true);
1185
it("shouldn't run disabled tests", function() {
1186
var xitSpecWasRun = false;
1187
var suite = env.describe('default current suite', function() {
1188
env.xit('disabled spec').runs(function () {
1189
xitSpecWasRun = true;
1192
env.it('enabled spec').runs(function () {
1194
expect(foo).toEqual('bar');
1199
expect(xitSpecWasRun).toEqual(false);
1202
it('shouldn\'t execute specs in disabled suites', function() {
1203
var spy = jasmine.createSpy();
1204
var disabledSuite = env.xdescribe('a disabled suite', function() {
1205
env.it('enabled spec, but should not be run', function() {
1210
disabledSuite.execute();
1212
expect(spy).not.toHaveBeenCalled();
1215
it('#explodes should throw an exception when it is called inside a spec', function() {
1216
var exceptionMessage = false;
1217
var anotherSuite = env.describe('Spec', function () {
1218
env.it('plodes', function() {
1223
exceptionMessage = e;
1225
expect(exceptionMessage).toNotEqual(false);
1229
anotherSuite.execute();
1231
expect(exceptionMessage).toEqual('explodes function should not have been called');
1234
it("should recover gracefully when there are errors in describe functions", function() {
1236
var superSimpleReporter = new jasmine.Reporter();
1237
superSimpleReporter.reportSpecResults = function(spec) {
1238
specs.push("Spec: " + spec.getFullName());
1239
var results = spec.results().getItems();
1240
for (var i = 0; i < results.length; i++) {
1241
var result = results[i];
1242
specs.push("Result: " + result);
1247
env.describe("outer1", function() {
1248
env.describe("inner1", function() {
1249
env.it("should thingy", function() {
1250
this.expect(true).toEqual(true);
1253
throw new Error("fake error");
1256
env.describe("inner2", function() {
1257
env.it("should other thingy", function() {
1258
this.expect(true).toEqual(true);
1262
throw new Error("fake error");
1268
env.describe("outer2", function() {
1269
env.it("should xxx", function() {
1270
this.expect(true).toEqual(true);
1274
env.addReporter(superSimpleReporter);
1277
expect(specs.join('')).toMatch(new RegExp(
1278
'Spec: outer1 inner1 should thingy.' +
1280
'Spec: outer1 inner1 encountered a declaration exception.' +
1281
'Result: Error: fake error.*' +
1282
'Spec: outer1 inner2 should other thingy.' +
1284
'Spec: outer1 encountered a declaration exception.' +
1285
'Result: Error: fake error.*' +
1286
'Spec: outer2 should xxx.' +