jasmine-core 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jasmine-core/boot/node_boot.js +1 -1
  3. data/lib/jasmine-core/jasmine-html.js +0 -35
  4. data/lib/jasmine-core/jasmine.css +0 -6
  5. data/lib/jasmine-core/jasmine.js +246 -36
  6. data/lib/jasmine-core/node_boot.js +1 -1
  7. data/lib/jasmine-core/version.rb +1 -1
  8. metadata +3 -88
  9. data/lib/jasmine-core/spec/core/CallTrackerSpec.js +0 -130
  10. data/lib/jasmine-core/spec/core/ClearStackSpec.js +0 -137
  11. data/lib/jasmine-core/spec/core/ClockSpec.js +0 -710
  12. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +0 -286
  13. data/lib/jasmine-core/spec/core/EnvSpec.js +0 -200
  14. data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +0 -120
  15. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +0 -46
  16. data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +0 -61
  17. data/lib/jasmine-core/spec/core/ExpectationSpec.js +0 -434
  18. data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +0 -110
  19. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +0 -259
  20. data/lib/jasmine-core/spec/core/MockDateSpec.js +0 -200
  21. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +0 -332
  22. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +0 -670
  23. data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +0 -140
  24. data/lib/jasmine-core/spec/core/SpecSpec.js +0 -407
  25. data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +0 -364
  26. data/lib/jasmine-core/spec/core/SpySpec.js +0 -177
  27. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +0 -202
  28. data/lib/jasmine-core/spec/core/StackTraceSpec.js +0 -166
  29. data/lib/jasmine-core/spec/core/SuiteSpec.js +0 -123
  30. data/lib/jasmine-core/spec/core/TimerSpec.js +0 -31
  31. data/lib/jasmine-core/spec/core/TreeProcessorSpec.js +0 -794
  32. data/lib/jasmine-core/spec/core/UserContextSpec.js +0 -54
  33. data/lib/jasmine-core/spec/core/UtilSpec.js +0 -105
  34. data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +0 -91
  35. data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +0 -76
  36. data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +0 -52
  37. data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +0 -47
  38. data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +0 -99
  39. data/lib/jasmine-core/spec/core/asymmetric_equality/StringMatchingSpec.js +0 -27
  40. data/lib/jasmine-core/spec/core/formatErrorMsgSpec.js +0 -13
  41. data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +0 -200
  42. data/lib/jasmine-core/spec/core/integration/CustomSpyStrategiesSpec.js +0 -138
  43. data/lib/jasmine-core/spec/core/integration/EnvSpec.js +0 -2344
  44. data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +0 -976
  45. data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +0 -47
  46. data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +0 -13
  47. data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +0 -43
  48. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +0 -645
  49. data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +0 -8
  50. data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +0 -93
  51. data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +0 -18
  52. data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +0 -38
  53. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanOrEqualSpec.js +0 -29
  54. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +0 -20
  55. data/lib/jasmine-core/spec/core/matchers/toBeLessThanOrEqualSpec.js +0 -29
  56. data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +0 -20
  57. data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +0 -37
  58. data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +0 -31
  59. data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +0 -17
  60. data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +0 -31
  61. data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +0 -17
  62. data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +0 -38
  63. data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +0 -18
  64. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +0 -26
  65. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +0 -785
  66. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +0 -99
  67. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +0 -47
  68. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledTimesSpec.js +0 -86
  69. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +0 -67
  70. data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +0 -43
  71. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +0 -315
  72. data/lib/jasmine-core/spec/core/matchers/toThrowMatchingSpec.js +0 -73
  73. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +0 -100
  74. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +0 -15
  75. data/lib/jasmine-core/spec/helpers/asyncAwait.js +0 -27
  76. data/lib/jasmine-core/spec/helpers/checkForMap.js +0 -37
  77. data/lib/jasmine-core/spec/helpers/checkForSet.js +0 -41
  78. data/lib/jasmine-core/spec/helpers/checkForSymbol.js +0 -28
  79. data/lib/jasmine-core/spec/helpers/checkForTypedArrays.js +0 -20
  80. data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +0 -6
  81. data/lib/jasmine-core/spec/helpers/integrationMatchers.js +0 -43
  82. data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +0 -30
  83. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +0 -1261
  84. data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +0 -18
  85. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +0 -37
  86. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +0 -27
  87. data/lib/jasmine-core/spec/html/QueryStringSpec.js +0 -72
  88. data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +0 -62
  89. data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +0 -39
  90. data/lib/jasmine-core/spec/html/matchers/toHaveClassSpec.js +0 -48
  91. data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +0 -101
  92. data/lib/jasmine-core/spec/performance/large_object_test.js +0 -36
  93. data/lib/jasmine-core/spec/performance/performance_test.js +0 -10
@@ -1,27 +0,0 @@
1
- describe("StringMatching", function() {
2
- it("matches a string against a provided regexp", function() {
3
- var matcher = new jasmineUnderTest.StringMatching(/foo/);
4
-
5
- expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
6
- expect(matcher.asymmetricMatch('barbaz')).toBe(false);
7
- });
8
-
9
- it("matches a string against provided string", function() {
10
- var matcher = new jasmineUnderTest.StringMatching('foo');
11
-
12
- expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
13
- expect(matcher.asymmetricMatch('barbaz')).toBe(false);
14
- });
15
-
16
- it("raises an Error when the expected is not a String or RegExp", function() {
17
- expect(function() {
18
- new jasmineUnderTest.StringMatching({});
19
- }).toThrowError(/not a String or a RegExp/);
20
- });
21
-
22
- it("jasmineToString's itself", function() {
23
- var matching = new jasmineUnderTest.StringMatching(/^foo/);
24
-
25
- expect(matching.jasmineToString()).toEqual("<jasmine.stringMatching(/^foo/)>");
26
- });
27
- });
@@ -1,13 +0,0 @@
1
- describe('formatErrorMsg', function () {
2
- it('should format an error with a domain', function() {
3
- var formator = jasmineUnderTest.formatErrorMsg('api');
4
- expect(formator('message')).toBe('api : message');
5
- expect(formator('message2')).toBe('api : message2');
6
- });
7
-
8
- it('should format an error with a domain and usage', function() {
9
- var formator = jasmineUnderTest.formatErrorMsg('api', 'with a param');
10
- expect(formator('message')).toBe('api : message\nUsage: with a param');
11
- expect(formator('message2')).toBe('api : message2\nUsage: with a param');
12
- });
13
- });
@@ -1,200 +0,0 @@
1
- describe("Custom Matchers (Integration)", function() {
2
- var env;
3
- var fakeTimer;
4
-
5
- beforeEach(function() {
6
- env = new jasmineUnderTest.Env();
7
- env.randomizeTests(false);
8
- });
9
-
10
- it("allows adding more matchers local to a spec", function(done) {
11
- env.it('spec defining a custom matcher', function() {
12
- env.addMatchers({
13
- matcherForSpec: function() {
14
- return {
15
- compare: function(actual, expected) {
16
- return { pass: false, message: "matcherForSpec: actual: " + actual + "; expected: " + expected };
17
- }
18
- }
19
- }
20
- });
21
-
22
- env.expect("zzz").matcherForSpec("yyy");
23
- });
24
-
25
- env.it("spec without custom matcher defined", function() {
26
- expect(env.expect("zzz").matcherForSpec).toBeUndefined();
27
- });
28
-
29
- var specDoneSpy = jasmine.createSpy("specDoneSpy");
30
- var expectations = function() {
31
- var firstSpecResult = specDoneSpy.calls.first().args[0];
32
- expect(firstSpecResult.status).toEqual("failed");
33
- expect(firstSpecResult.failedExpectations[0].message).toEqual("matcherForSpec: actual: zzz; expected: yyy");
34
- done();
35
- };
36
- env.addReporter({ specDone:specDoneSpy, jasmineDone: expectations});
37
-
38
- env.execute();
39
- });
40
-
41
- it("passes the spec if the custom matcher passes", function(done) {
42
- env.it("spec using custom matcher", function() {
43
- env.addMatchers({
44
- toBeReal: function() {
45
- return { compare: function() { return { pass: true }; } };
46
- }
47
- });
48
-
49
- env.expect(true).toBeReal();
50
- });
51
-
52
- var specExpectations = function(result) {
53
- expect(result.status).toEqual('passed');
54
- };
55
-
56
- env.addReporter({ specDone: specExpectations, jasmineDone: done });
57
- env.execute();
58
- });
59
-
60
- it("passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers", function(done) {
61
- env.it("spec using custom equality matcher", function() {
62
- var customEqualityFn = function(a, b) {
63
- // All "foo*" strings match each other.
64
- if (typeof a == "string" && typeof b == "string" &&
65
- a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
66
- return true;
67
- }
68
- };
69
-
70
- env.addCustomEqualityTester(customEqualityFn);
71
- env.expect({foo: 'fooValue'}).toEqual(jasmineUnderTest.objectContaining({foo: 'fooBar'}));
72
- env.expect(['fooValue', 'things']).toEqual(jasmineUnderTest.arrayContaining(['fooBar']));
73
- env.expect(['fooValue']).toEqual(jasmineUnderTest.arrayWithExactContents(['fooBar']));
74
- });
75
-
76
- var specExpectations = function(result) {
77
- expect(result.status).toEqual('passed');
78
- };
79
-
80
- env.addReporter({ specDone: specExpectations, jasmineDone: done });
81
- env.execute();
82
- });
83
-
84
- it("displays an appropriate failure message if a custom equality matcher fails", function(done) {
85
- env.it("spec using custom equality matcher", function() {
86
- var customEqualityFn = function(a, b) {
87
- // "foo" is not equal to anything
88
- if (a === 'foo' || b === 'foo') {
89
- return false;
90
- }
91
- };
92
-
93
- env.addCustomEqualityTester(customEqualityFn);
94
- env.expect({foo: 'foo'}).toEqual({foo: 'foo'});
95
- });
96
-
97
- var specExpectations = function(result) {
98
- expect(result.status).toEqual('failed');
99
- expect(result.failedExpectations[0].message).toEqual(
100
- "Expected $.foo = 'foo' to equal 'foo'."
101
- );
102
- };
103
-
104
- env.addReporter({ specDone: specExpectations, jasmineDone: done });
105
- env.execute();
106
- });
107
-
108
- it("uses the negative compare function for a negative comparison, if provided", function(done) {
109
- env.it("spec with custom negative comparison matcher", function() {
110
- env.addMatchers({
111
- toBeReal: function() {
112
- return {
113
- compare: function() { return { pass: true }; },
114
- negativeCompare: function() { return { pass: true }; }
115
- };
116
- }
117
- });
118
-
119
- env.expect(true).not.toBeReal();
120
- });
121
-
122
- var specExpectations = function(result) {
123
- expect(result.status).toEqual('passed');
124
- }
125
-
126
- env.addReporter({ specDone: specExpectations, jasmineDone: done });
127
- env.execute();
128
- });
129
-
130
- it("generates messages with the same rules as built in matchers absent a custom message", function(done) {
131
- env.it('spec with an expectation', function() {
132
- env.addMatchers({
133
- toBeReal: function() {
134
- return {
135
- compare: function() {
136
- return { pass: false };
137
- }
138
- }
139
- }
140
- });
141
-
142
- env.expect("a").toBeReal();
143
- });
144
-
145
- var specExpectations = function(result) {
146
- expect(result.failedExpectations[0].message).toEqual("Expected 'a' to be real.");
147
- };
148
-
149
- env.addReporter({ specDone: specExpectations, jasmineDone: done });
150
- env.execute();
151
- });
152
-
153
- it("passes the expected and actual arguments to the comparison function", function(done) {
154
- var argumentSpy = jasmine.createSpy("argument spy").and.returnValue({ pass: true });
155
-
156
- env.it('spec with an expectation', function () {
157
- env.addMatchers({
158
- toBeReal: function() {
159
- return { compare: argumentSpy };
160
- }
161
- });
162
-
163
- env.expect(true).toBeReal();
164
- env.expect(true).toBeReal("arg");
165
- env.expect(true).toBeReal("arg1", "arg2");
166
- });
167
-
168
- var specExpectations = function() {
169
- expect(argumentSpy).toHaveBeenCalledWith(true);
170
- expect(argumentSpy).toHaveBeenCalledWith(true, "arg");
171
- expect(argumentSpy).toHaveBeenCalledWith(true, "arg1", "arg2");
172
- };
173
-
174
- env.addReporter({ specDone: specExpectations, jasmineDone: done });
175
- env.execute();
176
- });
177
-
178
- it("passes the jasmine utility and current equality matchers to the expectation factory", function(done) {
179
- var matcherFactory = function() { return { compare: function() { return {pass: true}; }}; },
180
- argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory),
181
- customEqualityFn = function() { return true; };
182
-
183
-
184
- env.it("spec with expectation", function() {
185
- env.addCustomEqualityTester(customEqualityFn);
186
- env.addMatchers({
187
- toBeReal: argumentSpy
188
- });
189
-
190
- env.expect(true).toBeReal();
191
- });
192
-
193
- var specExpectations = function() {
194
- expect(argumentSpy).toHaveBeenCalledWith(jasmineUnderTest.matchersUtil, [customEqualityFn]);
195
- };
196
-
197
- env.addReporter({ specDone: specExpectations, jasmineDone: done });
198
- env.execute();
199
- });
200
- });
@@ -1,138 +0,0 @@
1
- describe('Custom Spy Strategies (Integration)', function() {
2
- var env;
3
-
4
- beforeEach(function() {
5
- env = new jasmineUnderTest.Env();
6
- env.randomizeTests(false);
7
- });
8
-
9
- it('allows adding more strategies local to a suite', function(done) {
10
- var plan = jasmine.createSpy('custom strategy plan')
11
- .and.returnValue(42);
12
- var strategy = jasmine.createSpy('custom strategy')
13
- .and.returnValue(plan);
14
-
15
- env.describe('suite defining a custom spy strategy', function() {
16
- env.beforeEach(function() {
17
- env.addSpyStrategy('frobnicate', strategy);
18
- });
19
-
20
- env.it('spec in the suite', function() {
21
- var spy = env.createSpy('something').and.frobnicate(17);
22
- expect(spy(1, 2, 3)).toEqual(42);
23
- expect(strategy).toHaveBeenCalledWith(17);
24
- expect(plan).toHaveBeenCalledWith(1, 2, 3);
25
- });
26
- });
27
-
28
- env.it('spec without custom strategy defined', function() {
29
- expect(env.createSpy('something').and.frobnicate).toBeUndefined();
30
- });
31
-
32
- function jasmineDone(result) {
33
- expect(result.overallStatus).toEqual('passed');
34
- done();
35
- }
36
-
37
- env.addReporter({ jasmineDone: jasmineDone });
38
- env.execute();
39
- });
40
-
41
- it('allows adding more strategies local to a spec', function(done) {
42
- var plan = jasmine.createSpy('custom strategy plan')
43
- .and.returnValue(42);
44
- var strategy = jasmine.createSpy('custom strategy')
45
- .and.returnValue(plan);
46
-
47
- env.it('spec defining a custom spy strategy', function() {
48
- env.addSpyStrategy('frobnicate', strategy);
49
- var spy = env.createSpy('something').and.frobnicate(17);
50
- expect(spy(1, 2, 3)).toEqual(42);
51
- expect(strategy).toHaveBeenCalledWith(17);
52
- expect(plan).toHaveBeenCalledWith(1, 2, 3);
53
- });
54
-
55
- env.it('spec without custom strategy defined', function() {
56
- expect(env.createSpy('something').and.frobnicate).toBeUndefined();
57
- });
58
-
59
- function jasmineDone(result) {
60
- expect(result.overallStatus).toEqual('passed');
61
- done();
62
- }
63
-
64
- env.addReporter({ jasmineDone: jasmineDone });
65
- env.execute();
66
- });
67
-
68
- it('allows using custom strategies on a per-argument basis', function(done) {
69
- var plan = jasmine.createSpy('custom strategy plan')
70
- .and.returnValue(42);
71
- var strategy = jasmine.createSpy('custom strategy')
72
- .and.returnValue(plan);
73
-
74
- env.it('spec defining a custom spy strategy', function() {
75
- env.addSpyStrategy('frobnicate', strategy);
76
- var spy = env.createSpy('something')
77
- .and.returnValue('no args return')
78
- .withArgs(1, 2, 3).and.frobnicate(17);
79
-
80
- expect(spy()).toEqual('no args return');
81
- expect(plan).not.toHaveBeenCalled();
82
- expect(spy(1, 2, 3)).toEqual(42);
83
- expect(plan).toHaveBeenCalledWith(1, 2, 3);
84
- });
85
-
86
- env.it('spec without custom strategy defined', function() {
87
- expect(env.createSpy('something').and.frobnicate).toBeUndefined();
88
- });
89
-
90
- function jasmineDone(result) {
91
- expect(result.overallStatus).toEqual('passed');
92
- done();
93
- }
94
-
95
- env.addReporter({ jasmineDone: jasmineDone });
96
- env.execute();
97
- });
98
-
99
- it('allows multiple custom strategies to be used', function(done) {
100
- var plan1 = jasmine.createSpy('plan 1').and.returnValue(42),
101
- strategy1 = jasmine.createSpy('strat 1').and.returnValue(plan1),
102
- plan2 = jasmine.createSpy('plan 2').and.returnValue(24),
103
- strategy2 = jasmine.createSpy('strat 2').and.returnValue(plan2),
104
- specDone = jasmine.createSpy('specDone');
105
-
106
- env.beforeEach(function() {
107
- env.addSpyStrategy('frobnicate', strategy1);
108
- env.addSpyStrategy('jiggle', strategy2);
109
- });
110
-
111
- env.it('frobnicates', function() {
112
- plan1.calls.reset();
113
- plan2.calls.reset();
114
- var spy = env.createSpy('spy').and.frobnicate();
115
- expect(spy()).toEqual(42);
116
- expect(plan1).toHaveBeenCalled();
117
- expect(plan2).not.toHaveBeenCalled();
118
- });
119
-
120
- env.it('jiggles', function() {
121
- plan1.calls.reset();
122
- plan2.calls.reset();
123
- var spy = env.createSpy('spy').and.jiggle();
124
- expect(spy()).toEqual(24);
125
- expect(plan1).not.toHaveBeenCalled();
126
- expect(plan2).toHaveBeenCalled();
127
- });
128
-
129
- function jasmineDone(result) {
130
- expect(result.overallStatus).toEqual('passed');
131
- expect(specDone.calls.count()).toBe(2);
132
- done();
133
- }
134
-
135
- env.addReporter({ jasmineDone: jasmineDone, specDone: specDone });
136
- env.execute();
137
- });
138
- });
@@ -1,2344 +0,0 @@
1
- describe("Env integration", function() {
2
- beforeEach(function() {
3
- jasmine.getEnv().registerIntegrationMatchers();
4
- });
5
-
6
- it("Suites execute as expected (no nesting)", function(done) {
7
- var env = new jasmineUnderTest.Env(),
8
- calls = [];
9
-
10
- var assertions = function() {
11
- expect(calls).toEqual([
12
- "with a spec",
13
- "and another spec"
14
- ]);
15
-
16
- done();
17
- };
18
-
19
- env.addReporter({ jasmineDone: assertions});
20
- env.randomizeTests(false);
21
-
22
- env.describe("A Suite", function() {
23
- env.it("with a spec", function() {
24
- calls.push("with a spec");
25
- });
26
- env.it("and another spec", function() {
27
- calls.push("and another spec");
28
- });
29
- });
30
-
31
- env.execute();
32
- });
33
-
34
- it("Nested Suites execute as expected", function(done) {
35
- var env = new jasmineUnderTest.Env(),
36
- calls = [];
37
-
38
- var assertions = function() {
39
- expect(calls).toEqual([
40
- 'an outer spec',
41
- 'an inner spec',
42
- 'another inner spec'
43
- ]);
44
-
45
- done();
46
- };
47
-
48
- env.addReporter({ jasmineDone: assertions });
49
- env.randomizeTests(false);
50
-
51
- env.describe("Outer suite", function() {
52
- env.it("an outer spec", function() {
53
- calls.push('an outer spec')
54
- });
55
- env.describe("Inner suite", function() {
56
- env.it("an inner spec", function() {
57
- calls.push('an inner spec');
58
- });
59
- env.it("another inner spec", function() {
60
- calls.push('another inner spec');
61
- });
62
- });
63
- });
64
-
65
- env.execute();
66
- });
67
-
68
- it("Multiple top-level Suites execute as expected", function(done) {
69
- var env = new jasmineUnderTest.Env(),
70
- calls = [];
71
-
72
- var assertions = function() {
73
- expect(calls).toEqual([
74
- 'an outer spec',
75
- 'an inner spec',
76
- 'another inner spec',
77
- 'a 2nd outer spec'
78
- ]);
79
-
80
- done();
81
- };
82
-
83
- env.addReporter({ jasmineDone: assertions });
84
- env.randomizeTests(false);
85
-
86
-
87
- env.describe("Outer suite", function() {
88
- env.it("an outer spec", function() {
89
- calls.push('an outer spec');
90
- });
91
- env.describe("Inner suite", function() {
92
- env.it("an inner spec", function() {
93
- calls.push('an inner spec');
94
- });
95
- env.it("another inner spec", function() {
96
- calls.push('another inner spec');
97
- });
98
- });
99
- });
100
-
101
- env.describe("Another outer suite", function() {
102
- env.it("a 2nd outer spec", function() {
103
- calls.push('a 2nd outer spec')
104
- });
105
- });
106
-
107
- env.execute();
108
- });
109
-
110
- it('explicitly fails a spec', function(done) {
111
- var env = new jasmineUnderTest.Env(),
112
- specDone = jasmine.createSpy('specDone');
113
-
114
- env.addReporter({
115
- specDone: specDone,
116
- jasmineDone: function() {
117
- expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
118
- description: 'has a default message',
119
- failedExpectations: [jasmine.objectContaining({
120
- message: 'Failed'
121
- })]
122
- }));
123
- expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
124
- description: 'specifies a message',
125
- failedExpectations: [jasmine.objectContaining({
126
- message: 'Failed: messy message'
127
- })]
128
- }));
129
- expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
130
- description: 'has a message and stack trace from an Error',
131
- failedExpectations: [jasmine.objectContaining({
132
- message: 'Failed: error message',
133
- stack: {
134
- asymmetricMatch: function(other) {
135
- if (!other) {
136
- // IE doesn't give us a stacktrace so just ignore it.
137
- return true;
138
- }
139
- var split = other.split('\n'),
140
- firstLine = split[0];
141
- if (firstLine.indexOf('error message') >= 0) {
142
- // Chrome inserts the message and a newline before the first stacktrace line.
143
- firstLine = split[1];
144
- }
145
- return firstLine.indexOf('EnvSpec') >= 0;
146
- }
147
- }
148
- })]
149
- }));
150
- expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
151
- description: 'pretty prints objects',
152
- failedExpectations: [jasmine.objectContaining({
153
- message: 'Failed: Object({ prop: \'value\', arr: [ \'works\', true ] })'
154
- })]
155
- }));
156
- done();
157
- }
158
- });
159
-
160
- env.describe('failing', function() {
161
- env.it('has a default message', function() {
162
- env.fail();
163
- });
164
-
165
- env.it('specifies a message', function() {
166
- env.fail('messy message');
167
- });
168
-
169
- env.it('has a message and stack trace from an Error', function() {
170
- env.fail(new Error('error message'));
171
- });
172
-
173
- env.it('pretty prints objects', function() {
174
- env.fail({prop: 'value', arr: ['works', true]});
175
- })
176
- });
177
-
178
- env.execute();
179
- });
180
-
181
- it("produces an understandable error message when 'fail' is used outside of a current spec", function(done) {
182
- var env = new jasmineUnderTest.Env(),
183
- reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
184
-
185
- reporter.jasmineDone.and.callFake(done);
186
- env.addReporter(reporter);
187
-
188
- env.describe("A Suite", function() {
189
- env.it("an async spec that is actually synchronous", function(underTestCallback) {
190
- underTestCallback();
191
- });
192
- expect(function() { env.fail(); }).toThrowError(/'fail' was used when there was no current spec/);
193
- });
194
-
195
- env.execute();
196
- });
197
-
198
-
199
- it("calls associated befores/specs/afters with the same 'this'", function(done) {
200
- var env = new jasmineUnderTest.Env();
201
-
202
- env.addReporter({jasmineDone: done});
203
- env.randomizeTests(false);
204
- env.describe("tests", function() {
205
- var firstTimeThrough = true, firstSpecContext, secondSpecContext;
206
-
207
- env.beforeEach(function() {
208
- if (firstTimeThrough) {
209
- firstSpecContext = this;
210
- } else {
211
- secondSpecContext = this;
212
- }
213
- expect(this).toEqual(new jasmineUnderTest.UserContext());
214
- });
215
-
216
- env.it("sync spec", function() {
217
- expect(this).toBe(firstSpecContext);
218
- });
219
-
220
- env.it("another sync spec", function() {
221
- expect(this).toBe(secondSpecContext);
222
- });
223
-
224
- env.afterEach(function() {
225
- if (firstTimeThrough) {
226
- expect(this).toBe(firstSpecContext);
227
- firstTimeThrough = false;
228
- } else {
229
- expect(this).toBe(secondSpecContext);
230
- }
231
- });
232
- });
233
-
234
- env.execute();
235
- });
236
-
237
- it("calls associated befores/its/afters with the same 'this' for an async spec", function(done) {
238
- var env = new jasmineUnderTest.Env();
239
-
240
- env.addReporter({jasmineDone: done});
241
-
242
- env.describe("with an async spec", function() {
243
- var specContext;
244
-
245
- env.beforeEach(function() {
246
- specContext = this;
247
- expect(this).toEqual(new jasmineUnderTest.UserContext());
248
- });
249
-
250
- env.it("sync spec", function(underTestCallback) {
251
- expect(this).toBe(specContext);
252
- underTestCallback();
253
- });
254
-
255
- env.afterEach(function() {
256
- expect(this).toBe(specContext);
257
- });
258
- });
259
-
260
- env.execute();
261
- });
262
-
263
- it("calls associated beforeAlls/afterAlls only once per suite", function(done) {
264
- var env = new jasmineUnderTest.Env(),
265
- before = jasmine.createSpy('beforeAll'),
266
- after = jasmine.createSpy('afterAll');
267
-
268
- env.addReporter({
269
- jasmineDone: function() {
270
- expect(after).toHaveBeenCalled();
271
- expect(after.calls.count()).toBe(1);
272
- expect(before.calls.count()).toBe(1);
273
- done();
274
- }
275
- });
276
-
277
- env.describe("with beforeAll and afterAll", function() {
278
- env.it("spec", function() {
279
- expect(before).toHaveBeenCalled();
280
- expect(after).not.toHaveBeenCalled();
281
- });
282
-
283
- env.it("another spec", function() {
284
- expect(before).toHaveBeenCalled();
285
- expect(after).not.toHaveBeenCalled();
286
- });
287
-
288
- env.beforeAll(before);
289
- env.afterAll(after);
290
- });
291
-
292
- env.execute();
293
- });
294
-
295
- it("calls associated beforeAlls/afterAlls only once per suite for async", function(done) {
296
- var env = new jasmineUnderTest.Env(),
297
- before = jasmine.createSpy('beforeAll'),
298
- after = jasmine.createSpy('afterAll');
299
-
300
- env.addReporter({
301
- jasmineDone: function() {
302
- expect(after).toHaveBeenCalled();
303
- expect(after.calls.count()).toBe(1);
304
- expect(before.calls.count()).toBe(1);
305
- done();
306
- }
307
- });
308
-
309
- env.describe("with beforeAll and afterAll", function() {
310
- env.it("spec", function() {
311
- expect(before).toHaveBeenCalled();
312
- expect(after).not.toHaveBeenCalled();
313
- });
314
-
315
- env.it("another spec", function() {
316
- expect(before).toHaveBeenCalled();
317
- expect(after).not.toHaveBeenCalled();
318
- });
319
-
320
- env.beforeAll(function(beforeCallbackUnderTest) {
321
- before();
322
- beforeCallbackUnderTest();
323
- });
324
-
325
- env.afterAll(function(afterCallbackUnderTest) {
326
- after();
327
- afterCallbackUnderTest();
328
- });
329
- });
330
-
331
- env.execute();
332
- });
333
-
334
- it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) {
335
- var env = new jasmineUnderTest.Env();
336
-
337
- env.addReporter({jasmineDone: done});
338
-
339
- env.describe("with beforeAll and afterAll", function() {
340
- env.beforeAll(function() {
341
- this.x = 1;
342
- });
343
-
344
- env.it("has an x at the root", function() {
345
- expect(this.x).toBe(1);
346
- });
347
-
348
- env.describe("child that deletes", function() {
349
- env.beforeAll(function() {
350
- expect(this.x).toBe(1);
351
- delete this.x;
352
- });
353
-
354
- env.it("has no x", function() {
355
- expect(this.x).not.toBeDefined();
356
- });
357
- });
358
-
359
- env.describe("child should still have x", function() {
360
- env.beforeAll(function(innerDone) {
361
- expect(this.x).toBe(1);
362
- innerDone();
363
- });
364
-
365
- env.it("has an x", function() {
366
- expect(this.x).toBe(1);
367
- delete this.x;
368
- });
369
-
370
- env.it("still has an x", function() {
371
- expect(this.x).toBe(1);
372
- });
373
-
374
- env.it("adds a y", function() {
375
- this.y = 2;
376
- expect(this.y).toBe(2);
377
- });
378
-
379
- env.it("doesn't have y that was added in sibling", function() {
380
- expect(this.y).not.toBeDefined();
381
- });
382
- });
383
- });
384
-
385
- env.execute();
386
- });
387
-
388
- it("tags top-level afterAll failures with a type", function(done) {
389
- var env = new jasmineUnderTest.Env();
390
-
391
- env.addReporter({jasmineDone: function(result) {
392
- expect(result.failedExpectations[0].globalErrorType).toEqual('afterAll');
393
- done();
394
- }});
395
-
396
- env.it('has a spec', function() {});
397
-
398
- env.afterAll(function() {
399
- throw 'nope';
400
- });
401
-
402
- env.execute();
403
- });
404
-
405
- it("does not tag suite afterAll failures with a type", function(done) {
406
- var env = new jasmineUnderTest.Env(),
407
- reporter = {
408
- jasmineDone: function() {
409
- expect(reporter.suiteDone).toHaveBeenCalled();
410
- done();
411
- },
412
- suiteDone: jasmine.createSpy('suiteDone').and.callFake(function(result) {
413
- expect(result.failedExpectations[0].globalErrorType).toBeFalsy();
414
- })
415
- };
416
-
417
- env.addReporter(reporter);
418
-
419
- env.describe('a suite', function() {
420
- env.it('has a spec', function() {});
421
-
422
- env.afterAll(function() {
423
- throw 'nope';
424
- });
425
- });
426
-
427
- env.execute();
428
- });
429
-
430
- it("when the beforeAll fails, error at suite level", function (done) {
431
- var env = new jasmineUnderTest.Env(),
432
- reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "suiteDone", "jasmineDone" ]);
433
-
434
- reporter.jasmineDone.and.callFake(function() {
435
- expect(reporter.specDone.calls.count()).toEqual(2);
436
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('A suite spec that will pass', []);
437
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('A suite nesting another spec to pass', []);
438
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('A suite', ['Expected 1 to be 2.']);
439
-
440
- done();
441
- });
442
-
443
- env.addReporter(reporter);
444
-
445
- env.describe('A suite', function(){
446
- env.beforeAll(function() {
447
- env.expect(1).toBe(2);
448
- });
449
-
450
- env.it("spec that will pass", function() {
451
- });
452
-
453
- env.describe("nesting", function() {
454
- env.it("another spec to pass", function() {
455
- });
456
- });
457
- });
458
-
459
- env.execute();
460
- });
461
-
462
- it("copes with async failures after done has been called", function(done) {
463
- var global = {
464
- setTimeout: function(fn, delay) { setTimeout(fn, delay) },
465
- clearTimeout: function(fn, delay) { clearTimeout(fn, delay) },
466
- };
467
- spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
468
- var env = new jasmineUnderTest.Env(),
469
- reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone", "suiteDone" ]);
470
-
471
- reporter.jasmineDone.and.callFake(function() {
472
- expect(reporter.specDone).not.toHaveFailedExpectationsForRunnable('A suite fails', ['fail thrown']);
473
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('A suite', ['fail thrown']);
474
- done();
475
- });
476
-
477
- env.addReporter(reporter);
478
-
479
- env.fdescribe('A suite', function() {
480
- env.it('fails', function(specDone) {
481
- setTimeout(function() {
482
- specDone();
483
- setTimeout(function() {
484
- setTimeout(function() {
485
- global.onerror('fail');
486
- });
487
- });
488
- });
489
- });
490
- });
491
-
492
- env.describe('Ignored', function() {
493
- env.it('is not run', function() {});
494
- });
495
-
496
- env.execute();
497
- });
498
-
499
- describe('suiteDone reporting', function(){
500
- it("reports when an afterAll fails an expectation", function(done) {
501
- var env = new jasmineUnderTest.Env(),
502
- reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
503
-
504
- reporter.jasmineDone.and.callFake(function() {
505
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [
506
- 'Expected 1 to equal 2.',
507
- 'Expected 2 to equal 3.'
508
- ]);
509
- done();
510
- });
511
-
512
- env.addReporter(reporter);
513
-
514
- env.describe('my suite', function() {
515
- env.it('my spec', function() {
516
- });
517
-
518
- env.afterAll(function() {
519
- env.expect(1).toEqual(2);
520
- env.expect(2).toEqual(3);
521
- });
522
- });
523
-
524
- env.execute();
525
- });
526
-
527
- it("if there are no specs, it still reports correctly", function(done) {
528
- var env = new jasmineUnderTest.Env(),
529
- reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
530
-
531
- reporter.jasmineDone.and.callFake(function() {
532
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('outer suite', [
533
- 'Expected 1 to equal 2.',
534
- 'Expected 2 to equal 3.'
535
- ]);
536
- done();
537
- });
538
-
539
- env.addReporter(reporter);
540
-
541
- env.describe('outer suite', function() {
542
- env.describe('inner suite', function() {
543
- env.it('spec', function(){ });
544
- });
545
-
546
- env.afterAll(function() {
547
- env.expect(1).toEqual(2);
548
- env.expect(2).toEqual(3);
549
- });
550
- });
551
-
552
- env.execute();
553
- });
554
-
555
- it("reports when afterAll throws an exception", function(done) {
556
- var env = new jasmineUnderTest.Env(),
557
- error = new Error('After All Exception'),
558
- reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
559
-
560
- reporter.jasmineDone.and.callFake(function() {
561
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [
562
- (/^Error: After All Exception/)
563
- ]);
564
- done();
565
- });
566
-
567
- env.addReporter(reporter);
568
-
569
- env.describe('my suite', function() {
570
- env.it('my spec', function() {
571
- });
572
-
573
- env.afterAll(function() {
574
- throw error;
575
- });
576
- });
577
-
578
- env.execute();
579
- });
580
-
581
- it("reports when an async afterAll fails an expectation", function(done) {
582
- var env = new jasmineUnderTest.Env(),
583
- reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
584
-
585
- reporter.jasmineDone.and.callFake(function() {
586
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [
587
- 'Expected 1 to equal 2.'
588
- ]);
589
- done();
590
- });
591
-
592
- env.addReporter(reporter);
593
-
594
- env.describe('my suite', function() {
595
- env.it('my spec', function() {
596
- });
597
-
598
- env.afterAll(function(afterAllDone) {
599
- env.expect(1).toEqual(2);
600
- afterAllDone();
601
- });
602
- });
603
-
604
- env.execute();
605
- });
606
-
607
- it("reports when an async afterAll throws an exception", function(done) {
608
- var env = new jasmineUnderTest.Env(),
609
- error = new Error('After All Exception'),
610
- reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
611
-
612
-
613
- reporter.jasmineDone.and.callFake(function() {
614
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('my suite', [
615
- (/^Error: After All Exception/)
616
- ]);
617
- done();
618
- });
619
-
620
- env.addReporter(reporter);
621
-
622
- env.describe('my suite', function() {
623
- env.it('my spec', function() {
624
- });
625
-
626
- env.afterAll(function(afterAllDone) {
627
- throw error;
628
- });
629
- });
630
-
631
- env.execute();
632
- });
633
- });
634
-
635
- it('reports expectation failures in global beforeAll', function(done) {
636
- var env = new jasmineUnderTest.Env(),
637
- reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']);
638
-
639
- reporter.jasmineDone.and.callFake(function(results) {
640
- expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]);
641
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('is a spec', []);
642
- done();
643
- });
644
-
645
- env.beforeAll(function() {
646
- env.expect(1).toBe(0);
647
- });
648
-
649
- env.it('is a spec', function() {
650
- env.expect(true).toBe(true);
651
- });
652
-
653
- env.addReporter(reporter);
654
-
655
- env.execute();
656
- });
657
-
658
- it('reports expectation failures in global afterAll', function(done) {
659
- var env = new jasmineUnderTest.Env(),
660
- reporter = jasmine.createSpyObj(['jasmineDone']);
661
-
662
- reporter.jasmineDone.and.callFake(function(results) {
663
- expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]);
664
- done();
665
- });
666
-
667
- env.afterAll(function() {
668
- env.expect(1).toBe(0);
669
- });
670
-
671
- env.it('is a spec', function() {
672
- env.expect(true).toBe(true);
673
- });
674
-
675
- env.addReporter(reporter);
676
-
677
- env.execute();
678
- });
679
-
680
- it("Allows specifying which specs and suites to run", function(done) {
681
- var env = new jasmineUnderTest.Env(),
682
- calls = [],
683
- suiteCallback = jasmine.createSpy('suite callback'),
684
- firstSpec,
685
- secondSuite;
686
-
687
- var assertions = function() {
688
- expect(calls).toEqual([
689
- 'third spec',
690
- 'first spec'
691
- ]);
692
- expect(suiteCallback).toHaveBeenCalled();
693
- done();
694
- };
695
-
696
- env.addReporter({jasmineDone: assertions, suiteDone: suiteCallback});
697
-
698
- env.describe("first suite", function() {
699
- firstSpec = env.it("first spec", function() {
700
- calls.push('first spec');
701
- });
702
- env.it("second spec", function() {
703
- calls.push('second spec');
704
- });
705
- });
706
-
707
- secondSuite = env.describe("second suite", function() {
708
- env.it("third spec", function() {
709
- calls.push('third spec');
710
- });
711
- });
712
-
713
- env.execute([secondSuite.id, firstSpec.id]);
714
- });
715
-
716
- it('runs before and after all functions for runnables provided to .execute()', function(done) {
717
- var env = new jasmineUnderTest.Env(),
718
- calls = [],
719
- first_spec,
720
- second_spec;
721
-
722
- var assertions = function() {
723
- expect(calls).toEqual([
724
- "before",
725
- "first spec",
726
- "second spec",
727
- "after"
728
- ]);
729
- done();
730
- };
731
-
732
- env.addReporter({jasmineDone: assertions});
733
-
734
- env.describe("first suite", function() {
735
- env.beforeAll(function() {
736
- calls.push("before");
737
- });
738
- env.afterAll(function() {
739
- calls.push("after")
740
- });
741
- first_spec = env.it("spec", function() {
742
- calls.push('first spec');
743
- });
744
- second_spec = env.it("spec 2", function() {
745
- calls.push("second spec");
746
- });
747
- });
748
-
749
- env.execute([first_spec.id, second_spec.id]);
750
- });
751
-
752
- it("Allows filtering out specs and suites to run programmatically", function(done) {
753
- var env = new jasmineUnderTest.Env(),
754
- calls = [],
755
- suiteCallback = jasmine.createSpy('suite callback'),
756
- firstSpec,
757
- secondSuite;
758
-
759
- var assertions = function() {
760
- expect(calls.length).toEqual(2);
761
- expect(calls).toEqual(jasmine.arrayContaining([
762
- 'first spec',
763
- 'second spec'
764
- ]));
765
- expect(suiteCallback).toHaveBeenCalled();
766
- done();
767
- };
768
-
769
- env.addReporter({jasmineDone: assertions, suiteDone: suiteCallback});
770
-
771
- env.describe("first suite", function() {
772
- env.it("first spec", function() {
773
- calls.push('first spec');
774
- });
775
- env.it("second spec", function() {
776
- calls.push('second spec');
777
- });
778
- });
779
-
780
- secondSuite = env.describe("second suite", function() {
781
- env.it("third spec", function() {
782
- calls.push('third spec');
783
- });
784
- });
785
-
786
- env.specFilter = function(spec) {
787
- return /^first suite/.test(spec.getFullName());
788
- };
789
-
790
- env.execute();
791
- });
792
-
793
- it("Functions can be spied on and have their calls tracked", function (done) {
794
- var env = new jasmineUnderTest.Env();
795
-
796
- var originalFunctionWasCalled = false;
797
- var subject = {
798
- spiedFunc: function() {
799
- originalFunctionWasCalled = true;
800
- return "original result";
801
- }
802
- };
803
-
804
- env.addReporter({jasmineDone: done});
805
-
806
- env.it("works with spies", function() {
807
- var spy = env.spyOn(subject, 'spiedFunc').and.returnValue("stubbed result");
808
-
809
- expect(subject.spiedFunc).toEqual(spy);
810
- expect(subject.spiedFunc.calls.any()).toEqual(false);
811
- expect(subject.spiedFunc.calls.count()).toEqual(0);
812
-
813
- subject.spiedFunc('foo');
814
-
815
- expect(subject.spiedFunc.calls.any()).toEqual(true);
816
- expect(subject.spiedFunc.calls.count()).toEqual(1);
817
- expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['foo']);
818
- expect(subject.spiedFunc.calls.mostRecent().object).toEqual(subject);
819
- expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual("stubbed result");
820
- expect(originalFunctionWasCalled).toEqual(false);
821
-
822
- subject.spiedFunc.and.callThrough();
823
- subject.spiedFunc('bar');
824
- expect(subject.spiedFunc.calls.count()).toEqual(2);
825
- expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['bar']);
826
- expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual("original result");
827
- expect(originalFunctionWasCalled).toEqual(true);
828
- });
829
-
830
- env.execute();
831
- });
832
-
833
- it('can be configured to allow respying on functions', function (done) {
834
- var env = new jasmineUnderTest.Env(),
835
- foo = {
836
- bar: function () {
837
- return 1;
838
- }
839
- };
840
-
841
- env.allowRespy(true);
842
- env.addReporter({ jasmineDone: done });
843
-
844
- env.describe('test suite', function(){
845
- env.it('spec 0', function(){
846
- env.spyOn(foo,'bar');
847
-
848
- var error = null;
849
-
850
- expect(function() {
851
- env.spyOn(foo, 'bar');
852
- }).not.toThrow();
853
- });
854
- });
855
-
856
- env.execute();
857
- });
858
-
859
- it('removes all spies added in a spec after the spec is complete', function(done) {
860
- var env = new jasmineUnderTest.Env(),
861
- originalFoo = function() {},
862
- testObj = {
863
- foo: originalFoo
864
- },
865
- firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
866
- env.spyOn(testObj, 'foo');
867
- }),
868
- secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
869
- expect(testObj.foo).toBe(originalFoo);
870
- });
871
- env.describe('test suite', function() {
872
- env.it('spec 0', firstSpec);
873
- env.it('spec 1', secondSpec);
874
- });
875
-
876
- var assertions = function() {
877
- expect(firstSpec).toHaveBeenCalled();
878
- expect(secondSpec).toHaveBeenCalled();
879
- done();
880
- };
881
-
882
- env.addReporter({ jasmineDone: assertions });
883
-
884
- env.execute();
885
- });
886
-
887
- it('removes all spies added in a suite after the suite is complete', function(done) {
888
- var env = new jasmineUnderTest.Env(),
889
- originalFoo = function() {},
890
- testObj = {
891
- foo: originalFoo
892
- };
893
-
894
- env.describe('test suite', function() {
895
- env.beforeAll(function() { env.spyOn(testObj, 'foo');})
896
-
897
- env.it('spec 0', function() {
898
- expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true);
899
- });
900
-
901
- env.it('spec 1', function() {
902
- expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true);
903
- });
904
- });
905
-
906
- env.describe('another suite', function() {
907
- env.it('spec 2', function() {
908
- expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(false);
909
- });
910
- });
911
-
912
- env.addReporter({ jasmineDone: done });
913
-
914
- env.execute();
915
- });
916
-
917
- it('removes a spy from the top suite after the run is complete', function(done) {
918
- var env = new jasmineUnderTest.Env(),
919
- originalFoo = function() {},
920
- testObj = {
921
- foo: originalFoo
922
- };
923
-
924
- env.beforeAll(function() {
925
- env.spyOn(testObj, 'foo');
926
- });
927
-
928
- env.it('spec', function() {
929
- expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true);
930
- });
931
-
932
- env.addReporter({
933
- jasmineDone: function() {
934
- expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(false);
935
- done();
936
- }
937
- });
938
-
939
- env.execute();
940
- });
941
-
942
- it("Mock clock can be installed and used in tests", function(done) {
943
- var globalSetTimeout = jasmine.createSpy('globalSetTimeout'),
944
- delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'),
945
- delayedFunctionForMockClock = jasmine.createSpy('delayedFunctionForMockClock'),
946
- env = new jasmineUnderTest.Env({global: { setTimeout: globalSetTimeout }});
947
-
948
- var assertions = function() {
949
- expect(delayedFunctionForMockClock).toHaveBeenCalled();
950
- expect(globalSetTimeout).toHaveBeenCalledWith(delayedFunctionForGlobalClock, 100);
951
-
952
- done();
953
- };
954
-
955
- env.addReporter({ jasmineDone: assertions });
956
- env.randomizeTests(false);
957
-
958
- env.describe("tests", function() {
959
- env.it("test with mock clock", function() {
960
- env.clock.install();
961
- env.clock.setTimeout(delayedFunctionForMockClock, 100);
962
- env.clock.tick(100);
963
- env.clock.uninstall();
964
- });
965
- env.it("test without mock clock", function() {
966
- env.clock.setTimeout(delayedFunctionForGlobalClock, 100);
967
- });
968
- });
969
-
970
- expect(globalSetTimeout).not.toHaveBeenCalled();
971
- expect(delayedFunctionForMockClock).not.toHaveBeenCalled();
972
-
973
- env.execute();
974
- });
975
-
976
- it("should run async specs in order, waiting for them to complete", function(done) {
977
- var env = new jasmineUnderTest.Env(),
978
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone']),
979
- mutatedVar;
980
-
981
- reporter.jasmineDone.and.callFake(function() {
982
- done();
983
- });
984
- env.addReporter(reporter);
985
-
986
- env.describe("tests", function() {
987
- env.beforeEach(function() {
988
- mutatedVar = 2;
989
- });
990
-
991
- env.it("async spec", function(underTestCallback) {
992
- setTimeout(function() {
993
- expect(mutatedVar).toEqual(2);
994
- underTestCallback();
995
- }, 0);
996
- });
997
-
998
- env.it("after async spec", function() {
999
- mutatedVar = 3;
1000
- });
1001
- });
1002
-
1003
- env.execute();
1004
- });
1005
-
1006
- describe("with a mock clock", function() {
1007
- var realSetTimeout;
1008
- beforeEach(function() {
1009
- this.originalTimeout = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL;
1010
- realSetTimeout = setTimeout;
1011
- jasmine.clock().install();
1012
- });
1013
-
1014
- afterEach(function() {
1015
- jasmine.clock().tick(1);
1016
- jasmine.clock().tick(1);
1017
- jasmine.clock().uninstall();
1018
- jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = this.originalTimeout;
1019
- });
1020
-
1021
- it("should wait a default interval before failing specs that haven't called done yet", function(done) {
1022
- var env = new jasmineUnderTest.Env(),
1023
- reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
1024
-
1025
- reporter.specDone.and.callFake(function(result) {
1026
- expect(result).toEqual(jasmine.objectContaining({status: 'failed'}));
1027
- realSetTimeout(function() {
1028
- jasmine.clock().tick(1);
1029
- }, 0);
1030
- });
1031
-
1032
- reporter.jasmineDone.and.callFake(function() {
1033
- expect(reporter.specDone.calls.count()).toEqual(1);
1034
- jasmine.clock().tick(1);
1035
- realSetTimeout(done);
1036
- });
1037
-
1038
- env.addReporter(reporter);
1039
- jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 8414;
1040
-
1041
- env.it("async spec that doesn't call done", function(underTestCallback) {
1042
- env.expect(true).toBeTruthy();
1043
- jasmine.clock().tick(8416);
1044
- jasmine.clock().tick(1);
1045
- });
1046
-
1047
- env.execute();
1048
- });
1049
-
1050
- it("should not use the mock clock for asynchronous timeouts", function(done){
1051
- var env = new jasmineUnderTest.Env(),
1052
- reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]),
1053
- clock = env.clock;
1054
-
1055
- reporter.specDone.and.callFake(function() {
1056
- realSetTimeout(function() {
1057
- jasmine.clock().tick(1);
1058
- }, 0);
1059
- });
1060
-
1061
- reporter.jasmineDone.and.callFake(function() {
1062
- expect(reporter.specDone).toHaveBeenCalledTimes(1);
1063
- expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(jasmine.objectContaining({status: 'passed'}));
1064
- jasmine.clock().tick(1);
1065
- realSetTimeout(done);
1066
- });
1067
-
1068
- env.addReporter(reporter);
1069
- jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 5;
1070
-
1071
- env.beforeAll(function() {
1072
- clock.install();
1073
- });
1074
-
1075
- env.afterAll(function() {
1076
- clock.uninstall();
1077
- });
1078
-
1079
- env.it("spec that should not time out", function(innerDone) {
1080
- clock.tick(6);
1081
- expect(true).toEqual(true);
1082
- realSetTimeout(innerDone);
1083
- });
1084
-
1085
- env.execute();
1086
- });
1087
-
1088
- it('should wait a custom interval before reporting async functions that fail to call done', function(done) {
1089
- var env = new jasmineUnderTest.Env(),
1090
- reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']),
1091
- timeoutFailure = (/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./);
1092
-
1093
- reporter.specDone.and.callFake(function(r) {
1094
- realSetTimeout(function() {
1095
- jasmine.clock().tick(1);
1096
- }, 0);
1097
- });
1098
-
1099
- reporter.suiteDone.and.callFake(function(r) {
1100
- realSetTimeout(function() {
1101
- jasmine.clock().tick(1);
1102
- }, 0);
1103
- });
1104
-
1105
- reporter.jasmineDone.and.callFake(function() {
1106
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('suite beforeAll', [ timeoutFailure ]);
1107
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('suite afterAll', [ timeoutFailure ]);
1108
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite beforeEach times out', [ timeoutFailure ]);
1109
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite afterEach times out', [ timeoutFailure ]);
1110
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite it times out', [ timeoutFailure ]);
1111
-
1112
- jasmine.clock().tick(1);
1113
- realSetTimeout(done);
1114
- });
1115
-
1116
- env.addReporter(reporter);
1117
- jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 10000;
1118
-
1119
- env.describe('suite', function() {
1120
- env.afterAll(function() {
1121
- realSetTimeout(function() {
1122
- try {
1123
- jasmine.clock().tick(10);
1124
- } catch(e) {
1125
- // don't worry if the clock is already uninstalled
1126
- }
1127
- }, 100);
1128
- });
1129
- env.describe('beforeAll', function() {
1130
- env.beforeAll(function(innerDone) {
1131
- realSetTimeout(function() {
1132
- jasmine.clock().tick(5001);
1133
- }, 0);
1134
- }, 5000);
1135
-
1136
- env.it('times out', function(innerDone) {
1137
- realSetTimeout(function() {
1138
- jasmine.clock().tick(1);
1139
- innerDone();
1140
- }, 0);
1141
- });
1142
- });
1143
-
1144
- env.describe('afterAll', function() {
1145
- env.afterAll(function(innerDone) {
1146
- realSetTimeout(function() {
1147
- jasmine.clock().tick(2001);
1148
- }, 0);
1149
- }, 2000);
1150
-
1151
- env.it('times out', function(innerDone) {
1152
- realSetTimeout(function() {
1153
- jasmine.clock().tick(1);
1154
- innerDone();
1155
- }, 0);
1156
- });
1157
- });
1158
-
1159
- env.describe('beforeEach', function() {
1160
- env.beforeEach(function(innerDone) {
1161
- realSetTimeout(function() {
1162
- jasmine.clock().tick(1001);
1163
- }, 0);
1164
- }, 1000);
1165
-
1166
- env.it('times out', function(innerDone) {
1167
- realSetTimeout(function() {
1168
- jasmine.clock().tick(1);
1169
- innerDone();
1170
- }, 0);
1171
- });
1172
- });
1173
-
1174
- env.describe('afterEach', function() {
1175
- env.afterEach(function(innerDone) {
1176
- realSetTimeout(function() {
1177
- jasmine.clock().tick(4001);
1178
- }, 0);
1179
- }, 4000);
1180
-
1181
- env.it('times out', function(innerDone) {
1182
- realSetTimeout(function() {
1183
- jasmine.clock().tick(1);
1184
- innerDone();
1185
- }, 0);
1186
- });
1187
- });
1188
-
1189
- env.it('it times out', function(innerDone) {
1190
- realSetTimeout(function() {
1191
- jasmine.clock().tick(6001);
1192
- }, 0);
1193
- }, 6000);
1194
- });
1195
-
1196
- env.execute();
1197
- });
1198
- });
1199
-
1200
- it('explicitly fails an async spec', function(done) {
1201
- var env = new jasmineUnderTest.Env(),
1202
- specDone = jasmine.createSpy('specDone');
1203
-
1204
- env.addReporter({
1205
- specDone: specDone,
1206
- jasmineDone: function() {
1207
- expect(specDone).toHaveFailedExpectationsForRunnable('failing has a default message',
1208
- ['Failed']
1209
- );
1210
- expect(specDone).toHaveFailedExpectationsForRunnable('failing specifies a message',
1211
- ['Failed: messy message']
1212
- );
1213
- expect(specDone).toHaveFailedExpectationsForRunnable('failing fails via the done callback',
1214
- ['Failed: done failed']
1215
- );
1216
- expect(specDone).toHaveFailedExpectationsForRunnable('failing has a message from an Error',
1217
- ['Failed: error message']
1218
- );
1219
- expect(specDone).toHaveFailedExpectationsForRunnable('failing has a message from an Error to done',
1220
- ['Failed: done error']
1221
- );
1222
-
1223
- setTimeout(done);
1224
- }
1225
- });
1226
-
1227
- env.describe('failing', function() {
1228
- env.it('has a default message', function(innerDone) {
1229
- setTimeout(function() {
1230
- env.fail();
1231
- innerDone();
1232
- }, 1);
1233
- });
1234
-
1235
- env.it('specifies a message', function(innerDone) {
1236
- setTimeout(function() {
1237
- env.fail('messy message');
1238
- innerDone();
1239
- }, 1);
1240
- });
1241
-
1242
- env.it('fails via the done callback', function(innerDone) {
1243
- setTimeout(function() {
1244
- innerDone.fail('done failed');
1245
- }, 1);
1246
- });
1247
-
1248
- env.it('has a message from an Error', function(innerDone) {
1249
- setTimeout(function() {
1250
- env.fail(new Error('error message'));
1251
- innerDone();
1252
- }, 1);
1253
- });
1254
-
1255
- env.it('has a message from an Error to done', function(innerDone) {
1256
- setTimeout(function() {
1257
- innerDone(new Error('done error'));
1258
- }, 1);
1259
- });
1260
- });
1261
-
1262
- env.execute();
1263
- });
1264
-
1265
- describe('focused tests', function() {
1266
- it('should only run the focused tests', function(done) {
1267
- var env = new jasmineUnderTest.Env(),
1268
- calls = [];
1269
-
1270
- var assertions = function() {
1271
- expect(calls).toEqual(['focused']);
1272
- done();
1273
- };
1274
-
1275
- env.addReporter({jasmineDone: assertions});
1276
-
1277
- env.describe('a suite', function() {
1278
- env.fit('is focused', function() {
1279
- calls.push('focused');
1280
- });
1281
-
1282
- env.it('is not focused', function() {
1283
- calls.push('freakout');
1284
- })
1285
- });
1286
-
1287
- env.execute();
1288
- });
1289
-
1290
- it('should only run focused suites', function(done){
1291
- var env = new jasmineUnderTest.Env(),
1292
- calls = [];
1293
-
1294
- var assertions = function() {
1295
- expect(calls).toEqual(['focused']);
1296
- done();
1297
- };
1298
-
1299
- env.addReporter({jasmineDone: assertions});
1300
-
1301
- env.fdescribe('a focused suite', function() {
1302
- env.it('is focused', function() {
1303
- calls.push('focused');
1304
- });
1305
- });
1306
-
1307
- env.describe('a regular suite', function() {
1308
- env.it('is not focused', function() {
1309
- calls.push('freakout');
1310
- })
1311
- });
1312
-
1313
- env.execute();
1314
- });
1315
-
1316
- it('should run focused tests inside an xdescribe', function(done) {
1317
- var env = new jasmineUnderTest.Env(),
1318
- reporter = jasmine.createSpyObj('fakeReporter', [
1319
- "jasmineStarted",
1320
- "jasmineDone",
1321
- "suiteStarted",
1322
- "suiteDone",
1323
- "specStarted",
1324
- "specDone"
1325
- ]);
1326
-
1327
- reporter.jasmineDone.and.callFake(function() {
1328
- expect(reporter.jasmineStarted).toHaveBeenCalledWith({
1329
- totalSpecsDefined: 1,
1330
- order: jasmine.any(jasmineUnderTest.Order)
1331
- });
1332
-
1333
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
1334
- description: 'with a fit spec',
1335
- status: 'failed'
1336
- }));
1337
-
1338
- done();
1339
- });
1340
-
1341
- env.addReporter(reporter);
1342
-
1343
- env.xdescribe("xd suite", function() {
1344
- env.fit("with a fit spec", function() {
1345
- env.expect(true).toBe(false);
1346
- });
1347
- });
1348
-
1349
- env.execute();
1350
- });
1351
-
1352
- it('should run focused suites inside an xdescribe', function(done) {
1353
- var env = new jasmineUnderTest.Env(),
1354
- reporter = jasmine.createSpyObj('fakeReporter', [
1355
- "jasmineStarted",
1356
- "jasmineDone",
1357
- "suiteStarted",
1358
- "suiteDone",
1359
- "specStarted",
1360
- "specDone"
1361
- ]);
1362
-
1363
- reporter.jasmineDone.and.callFake(function() {
1364
- expect(reporter.jasmineStarted).toHaveBeenCalledWith({
1365
- totalSpecsDefined: 1,
1366
- order: jasmine.any(jasmineUnderTest.Order)
1367
- });
1368
-
1369
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
1370
- description: 'with a spec',
1371
- status: 'failed'
1372
- }));
1373
-
1374
- done();
1375
- });
1376
-
1377
- env.addReporter(reporter);
1378
-
1379
- env.xdescribe("xd suite", function() {
1380
- env.fdescribe("fd suite", function() {
1381
- env.it("with a spec", function() {
1382
- env.expect(true).toBe(false);
1383
- });
1384
- });
1385
- });
1386
-
1387
- env.execute();
1388
- });
1389
- });
1390
-
1391
- it("should report as expected", function(done) {
1392
- var env = new jasmineUnderTest.Env(),
1393
- reporter = jasmine.createSpyObj('fakeReporter', [
1394
- "jasmineStarted",
1395
- "jasmineDone",
1396
- "suiteStarted",
1397
- "suiteDone",
1398
- "specStarted",
1399
- "specDone"
1400
- ]);
1401
-
1402
- reporter.jasmineDone.and.callFake(function() {
1403
- expect(reporter.jasmineStarted).toHaveBeenCalledWith({
1404
- totalSpecsDefined: 5,
1405
- order: jasmine.any(jasmineUnderTest.Order)
1406
- });
1407
-
1408
- expect(reporter.specDone.calls.count()).toBe(5);
1409
-
1410
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
1411
- description: 'with a top level spec',
1412
- status: 'passed'
1413
- }));
1414
-
1415
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
1416
- description: "with an x'ed spec",
1417
- status: 'pending'
1418
- }));
1419
-
1420
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
1421
- description: 'with a spec',
1422
- status: 'failed'
1423
- }));
1424
-
1425
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
1426
- description: 'is pending',
1427
- status: 'pending'
1428
- }));
1429
-
1430
- var suiteResult = reporter.suiteStarted.calls.argsFor(0)[0];
1431
- expect(suiteResult.description).toEqual("A Suite");
1432
-
1433
- done();
1434
- });
1435
-
1436
- env.addReporter(reporter);
1437
-
1438
- env.describe("A Suite", function() {
1439
- env.it("with a top level spec", function() {
1440
- env.expect(true).toBe(true);
1441
- });
1442
- env.describe("with a nested suite", function() {
1443
- env.xit("with an x'ed spec", function() {
1444
- env.expect(true).toBe(true);
1445
- });
1446
- env.it("with a spec", function() {
1447
- env.expect(true).toBe(false);
1448
- });
1449
- });
1450
-
1451
- env.describe('with only non-executable specs', function() {
1452
- env.it('is pending');
1453
- env.xit('is xed', function() {
1454
- env.expect(true).toBe(true);
1455
- });
1456
- });
1457
- });
1458
-
1459
- env.execute();
1460
- });
1461
-
1462
- it("should report the random seed at the beginning and end of execution", function(done) {
1463
- var env = new jasmineUnderTest.Env(),
1464
- reporter = jasmine.createSpyObj('fakeReporter', [
1465
- "jasmineStarted",
1466
- "jasmineDone",
1467
- "suiteStarted",
1468
- "suiteDone",
1469
- "specStarted",
1470
- "specDone"
1471
- ]);
1472
- env.randomizeTests(true);
1473
- env.seed('123456');
1474
-
1475
- reporter.jasmineDone.and.callFake(function(doneArg) {
1476
- expect(reporter.jasmineStarted).toHaveBeenCalled();
1477
- var startedArg = reporter.jasmineStarted.calls.argsFor(0)[0];
1478
- expect(startedArg.order.random).toEqual(true);
1479
- expect(startedArg.order.seed).toEqual('123456');
1480
-
1481
- expect(doneArg.order.random).toEqual(true);
1482
- expect(doneArg.order.seed).toEqual('123456');
1483
- done();
1484
- });
1485
-
1486
- env.addReporter(reporter);
1487
- env.randomizeTests(true);
1488
- env.execute();
1489
- });
1490
-
1491
- it('should report pending spec messages', function(done) {
1492
- var env = new jasmineUnderTest.Env(),
1493
- reporter = jasmine.createSpyObj('fakeReporter', [
1494
- 'specDone',
1495
- 'jasmineDone'
1496
- ]);
1497
-
1498
- reporter.jasmineDone.and.callFake(function() {
1499
- var specStatus = reporter.specDone.calls.argsFor(0)[0];
1500
-
1501
- expect(specStatus.status).toBe('pending');
1502
- expect(specStatus.pendingReason).toBe('with a message');
1503
-
1504
- done();
1505
- });
1506
-
1507
- env.addReporter(reporter);
1508
-
1509
- env.it('will be pending', function() {
1510
- env.pending('with a message');
1511
- });
1512
-
1513
- env.execute();
1514
- });
1515
-
1516
- it('should report pending spec messages from promise-returning functions', function(done) {
1517
- function StubPromise(fn) {
1518
- try {
1519
- fn();
1520
- } catch (e) {
1521
- this.exception = e;
1522
- }
1523
- }
1524
-
1525
- StubPromise.prototype.then = function(resolve, reject) {
1526
- reject(this.exception);
1527
- };
1528
-
1529
- var env = new jasmineUnderTest.Env(),
1530
- reporter = jasmine.createSpyObj('fakeReporter', [
1531
- 'specDone',
1532
- 'jasmineDone'
1533
- ]);
1534
-
1535
- reporter.jasmineDone.and.callFake(function() {
1536
- var specStatus = reporter.specDone.calls.argsFor(0)[0];
1537
-
1538
- expect(specStatus.status).toBe('pending');
1539
- expect(specStatus.pendingReason).toBe('with a message');
1540
-
1541
- done();
1542
- });
1543
-
1544
- env.addReporter(reporter);
1545
-
1546
- env.it('will be pending', function() {
1547
- return new StubPromise(function() {
1548
- env.pending('with a message');
1549
- });
1550
- });
1551
-
1552
- env.execute();
1553
- });
1554
-
1555
- it('should report using fallback reporter', function(done) {
1556
- var env = new jasmineUnderTest.Env(),
1557
- reporter = jasmine.createSpyObj('fakeReporter', [
1558
- 'specDone',
1559
- 'jasmineDone'
1560
- ]);
1561
-
1562
- reporter.jasmineDone.and.callFake(function() {
1563
- expect(reporter.specDone).toHaveBeenCalled();
1564
-
1565
- done();
1566
- });
1567
-
1568
- env.provideFallbackReporter(reporter);
1569
-
1570
- env.it('will be pending', function() {
1571
- env.pending('with a message');
1572
- });
1573
-
1574
- env.execute();
1575
- });
1576
-
1577
- it('should report xdescribes as expected', function(done) {
1578
- var env = new jasmineUnderTest.Env(),
1579
- reporter = jasmine.createSpyObj('fakeReporter', [
1580
- "jasmineStarted",
1581
- "jasmineDone",
1582
- "suiteStarted",
1583
- "suiteDone",
1584
- "specStarted",
1585
- "specDone"
1586
- ]);
1587
-
1588
- reporter.jasmineDone.and.callFake(function() {
1589
- expect(reporter.jasmineStarted).toHaveBeenCalledWith({
1590
- totalSpecsDefined: 1,
1591
- order: jasmine.any(jasmineUnderTest.Order)
1592
- });
1593
-
1594
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({ status: 'pending' }));
1595
- expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({ description: 'xd out', status: 'pending' }));
1596
- expect(reporter.suiteDone.calls.count()).toBe(4);
1597
-
1598
- done();
1599
- });
1600
-
1601
- env.addReporter(reporter);
1602
-
1603
- env.describe("A Suite", function() {
1604
- env.describe("nested", function() {
1605
- env.xdescribe("xd out", function() {
1606
- env.describe("nested again", function() {
1607
- env.it("with a spec", function() {
1608
- env.expect(true).toBe(false);
1609
- });
1610
- });
1611
- });
1612
- });
1613
- });
1614
-
1615
- env.execute();
1616
- });
1617
-
1618
- it("should be possible to get full name from a spec", function() {
1619
- var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
1620
- topLevelSpec, nestedSpec, doublyNestedSpec;
1621
-
1622
- env.describe("my tests", function() {
1623
- topLevelSpec = env.it("are sometimes top level", function() {
1624
- });
1625
- env.describe("are sometimes", function() {
1626
- nestedSpec = env.it("singly nested", function() {
1627
- });
1628
- env.describe("even", function() {
1629
- doublyNestedSpec = env.it("doubly nested", function() {
1630
- });
1631
- });
1632
- });
1633
- });
1634
-
1635
- expect(topLevelSpec.getFullName()).toBe("my tests are sometimes top level");
1636
- expect(nestedSpec.getFullName()).toBe("my tests are sometimes singly nested");
1637
- expect(doublyNestedSpec.getFullName()).toBe("my tests are sometimes even doubly nested");
1638
- });
1639
-
1640
- it("Custom equality testers should be per spec", function(done) {
1641
- var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
1642
- reporter = jasmine.createSpyObj('fakeReporter', [
1643
- "jasmineDone",
1644
- "specDone"
1645
- ]);
1646
-
1647
- reporter.jasmineDone.and.callFake(function() {
1648
- var firstSpecResult = reporter.specDone.calls.first().args[0],
1649
- secondSpecResult = reporter.specDone.calls.mostRecent().args[0];
1650
-
1651
- expect(firstSpecResult.status).toEqual("passed");
1652
- expect(secondSpecResult.status).toEqual("failed");
1653
-
1654
- done();
1655
- });
1656
-
1657
- env.addReporter(reporter);
1658
- env.randomizeTests(false);
1659
-
1660
- env.describe("testing custom equality testers", function() {
1661
- env.it("with a custom tester", function() {
1662
- env.addCustomEqualityTester(function(a, b) { return true; });
1663
- env.expect("a").toEqual("b");
1664
- });
1665
-
1666
- env.it("without a custom tester", function() {
1667
- env.expect("a").toEqual("b");
1668
- });
1669
- });
1670
-
1671
- env.execute();
1672
- });
1673
-
1674
- it("Custom equality testers should be per suite", function(done) {
1675
- var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
1676
- reporter = jasmine.createSpyObj('fakeReporter', [
1677
- "jasmineDone",
1678
- "specDone"
1679
- ]);
1680
-
1681
- reporter.jasmineDone.and.callFake(function() {
1682
- var firstSpecResult = reporter.specDone.calls.first().args[0],
1683
- secondSpecResult = reporter.specDone.calls.argsFor(0)[0],
1684
- thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];
1685
-
1686
- expect(firstSpecResult.status).toEqual("passed");
1687
- expect(secondSpecResult.status).toEqual("passed");
1688
- expect(thirdSpecResult.status).toEqual("failed");
1689
-
1690
- done();
1691
- });
1692
-
1693
- env.addReporter(reporter);
1694
- env.randomizeTests(false);
1695
-
1696
- env.describe("testing custom equality testers", function() {
1697
- env.beforeAll(function() { env.addCustomEqualityTester(function(a, b) { return true; }); });
1698
-
1699
- env.it("with a custom tester", function() {
1700
- env.expect("a").toEqual("b");
1701
- });
1702
-
1703
- env.it("with the same custom tester", function() {
1704
- env.expect("a").toEqual("b");
1705
- });
1706
- });
1707
-
1708
- env.describe("another suite", function() {
1709
- env.it("without the custom tester", function(){
1710
- env.expect("a").toEqual("b");
1711
- });
1712
- });
1713
-
1714
- env.execute();
1715
- });
1716
-
1717
- it("Custom equality testers for toContain should be per spec", function(done) {
1718
- var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
1719
- reporter = jasmine.createSpyObj('fakeReporter', [
1720
- "jasmineDone",
1721
- "specDone"
1722
- ]);
1723
-
1724
- reporter.jasmineDone.and.callFake(function() {
1725
- var firstSpecResult = reporter.specDone.calls.first().args[0],
1726
- secondSpecResult = reporter.specDone.calls.mostRecent().args[0];
1727
-
1728
- expect(firstSpecResult.status).toEqual("passed");
1729
- expect(secondSpecResult.status).toEqual("failed");
1730
-
1731
- done();
1732
- });
1733
-
1734
- env.addReporter(reporter);
1735
- env.randomizeTests(false);
1736
-
1737
- env.describe("testing custom equality testers", function() {
1738
- env.it("with a custom tester", function() {
1739
- env.addCustomEqualityTester(function(a, b) { return true; });
1740
- env.expect(["a"]).toContain("b");
1741
- });
1742
-
1743
- env.it("without a custom tester", function() {
1744
- env.expect(["a"]).toContain("b");
1745
- });
1746
- });
1747
-
1748
- env.execute();
1749
- });
1750
-
1751
- it("produces an understandable error message when an 'expect' is used outside of a current spec", function(done) {
1752
- var env = new jasmineUnderTest.Env(),
1753
- reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
1754
-
1755
- reporter.jasmineDone.and.callFake(done);
1756
- env.addReporter(reporter);
1757
-
1758
- env.describe("A Suite", function() {
1759
- env.it("an async spec that is actually synchronous", function(underTestCallback) {
1760
- underTestCallback();
1761
- });
1762
- expect(function() { env.expect('a').toEqual('a'); }).toThrowError(/'expect' was used when there was no current spec/);
1763
- });
1764
-
1765
- env.execute();
1766
- });
1767
-
1768
- it("Custom equality testers for toContain should be per suite", function(done) {
1769
- var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
1770
- reporter = jasmine.createSpyObj('fakeReporter', [
1771
- "jasmineDone",
1772
- "specDone"
1773
- ]);
1774
-
1775
- reporter.jasmineDone.and.callFake(function() {
1776
- var firstSpecResult = reporter.specDone.calls.first().args[0],
1777
- secondSpecResult = reporter.specDone.calls.argsFor(1)[0],
1778
- thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];
1779
-
1780
- expect(firstSpecResult.status).toEqual("passed");
1781
- expect(secondSpecResult.status).toEqual("passed");
1782
- expect(thirdSpecResult.status).toEqual("failed");
1783
-
1784
- done();
1785
- });
1786
-
1787
- env.addReporter(reporter);
1788
- env.randomizeTests(false);
1789
-
1790
- env.describe("testing custom equality testers", function() {
1791
- env.beforeAll(function() { env.addCustomEqualityTester(function(a, b) { return true; })});
1792
-
1793
- env.it("with a custom tester", function() {
1794
- env.expect(["a"]).toContain("b");
1795
- });
1796
-
1797
- env.it("also with the custom tester", function() {
1798
- env.expect(["a"]).toContain("b");
1799
- });
1800
- });
1801
-
1802
- env.describe("another suite", function() {
1803
- env.it("without the custom tester", function() {
1804
- env.expect(["a"]).toContain("b");
1805
- });
1806
- });
1807
-
1808
- env.execute();
1809
- });
1810
-
1811
- it("Custom matchers should be per spec", function(done) {
1812
- var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
1813
- matchers = {
1814
- toFoo: function() {}
1815
- };
1816
-
1817
- env.describe("testing custom matchers", function() {
1818
- env.it("with a custom matcher", function() {
1819
- env.addMatchers(matchers);
1820
- expect(env.expect().toFoo).toBeDefined();
1821
- });
1822
-
1823
- env.it("without a custom matcher", function() {
1824
- expect(env.expect().toFoo).toBeUndefined();
1825
- });
1826
- });
1827
-
1828
- env.addReporter({jasmineDone: done});
1829
-
1830
- env.execute();
1831
- });
1832
-
1833
- it("Custom matchers should be per suite", function(done) {
1834
- var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
1835
- matchers = {
1836
- toFoo: function() {}
1837
- };
1838
-
1839
- env.describe("testing custom matchers", function() {
1840
- env.beforeAll(function() { env.addMatchers(matchers); });
1841
-
1842
- env.it("with a custom matcher", function() {
1843
- expect(env.expect().toFoo).toBeDefined();
1844
- });
1845
-
1846
- env.it("with the same custom matcher", function() {
1847
- expect(env.expect().toFoo).toBeDefined();
1848
- });
1849
- });
1850
-
1851
- env.describe("another suite", function() {
1852
- env.it("no longer has the custom matcher", function() {
1853
- expect(env.expect().toFoo).not.toBeDefined();
1854
- });
1855
- });
1856
-
1857
- env.addReporter({jasmineDone: done});
1858
-
1859
- env.execute();
1860
- });
1861
-
1862
- it('throws an exception if you try to create a spy outside of a runnable', function (done) {
1863
- var env = new jasmineUnderTest.Env(),
1864
- obj = {fn: function () {}},
1865
- exception;
1866
-
1867
- env.describe("a suite", function () {
1868
- try {
1869
- env.spyOn(obj, 'fn');
1870
- } catch(e) {
1871
- exception = e;
1872
- }
1873
- });
1874
-
1875
- var assertions = function() {
1876
- expect(exception.message).toBe('Spies must be created in a before function or a spec');
1877
- done();
1878
- };
1879
-
1880
- env.addReporter({jasmineDone: assertions});
1881
-
1882
- env.execute();
1883
- });
1884
-
1885
- it('throws an exception if you try to add a matcher outside of a runnable', function (done) {
1886
- var env = new jasmineUnderTest.Env(),
1887
- obj = {fn: function () {}},
1888
- exception;
1889
-
1890
- env.describe("a suite", function () {
1891
- try {
1892
- env.addMatchers({myMatcher: function(actual,expected){return false;}});
1893
- } catch(e) {
1894
- exception = e;
1895
- }
1896
- });
1897
-
1898
- var assertions = function() {
1899
- expect(exception.message).toBe('Matchers must be added in a before function or a spec');
1900
- done();
1901
- };
1902
-
1903
- env.addReporter({jasmineDone: assertions});
1904
-
1905
- env.execute();
1906
- });
1907
-
1908
- it('throws an exception if you try to add a custom equality outside of a runnable', function (done) {
1909
- var env = new jasmineUnderTest.Env(),
1910
- obj = {fn: function () {}},
1911
- exception;
1912
-
1913
- env.describe("a suite", function () {
1914
- try {
1915
- env.addCustomEqualityTester(function(first, second) {return true;});
1916
- } catch(e) {
1917
- exception = e;
1918
- }
1919
- });
1920
-
1921
- var assertions = function() {
1922
- expect(exception.message).toBe('Custom Equalities must be added in a before function or a spec');
1923
- done();
1924
- };
1925
-
1926
- env.addReporter({jasmineDone: assertions});
1927
-
1928
- env.execute();
1929
- });
1930
-
1931
- it("should associate errors thrown from async code with the correct runnable", function(done) {
1932
- var env = new jasmineUnderTest.Env(),
1933
- reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone','specDone']);
1934
-
1935
- reporter.jasmineDone.and.callFake(function() {
1936
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('async suite', [
1937
- /^(((Uncaught )?Error: suite( thrown)?)|(suite thrown))$/
1938
- ]);
1939
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite async spec', [
1940
- /^(((Uncaught )?Error: spec( thrown)?)|(spec thrown))$/
1941
- ]);
1942
- done();
1943
- });
1944
-
1945
- env.addReporter(reporter);
1946
-
1947
- env.describe('async suite', function() {
1948
- env.afterAll(function(innerDone) {
1949
- setTimeout(function() { throw new Error('suite'); }, 1);
1950
- }, 10);
1951
-
1952
- env.it('spec', function() {});
1953
- });
1954
-
1955
- env.describe('suite', function() {
1956
- env.it('async spec', function(innerDone) {
1957
- setTimeout(function() { throw new Error('spec'); }, 1);
1958
- }, 10);
1959
- });
1960
-
1961
- env.execute();
1962
- });
1963
-
1964
- it('should throw on suites/specs/befores/afters nested in methods other than \'describe\'', function(done) {
1965
- var env = new jasmineUnderTest.Env(),
1966
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
1967
-
1968
- reporter.jasmineDone.and.callFake(function() {
1969
- var msg = /\'.*\' should only be used in \'describe\' function/;
1970
-
1971
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite describe', [msg]);
1972
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite xdescribe', [msg]);
1973
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite fdescribe', [msg]);
1974
-
1975
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('spec it', [msg]);
1976
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('spec xit', [msg]);
1977
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('spec fit', [msg]);
1978
-
1979
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('beforeAll', [msg]);
1980
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('beforeEach spec', [msg]);
1981
-
1982
- expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('afterAll', [msg]);
1983
- expect(reporter.specDone).toHaveFailedExpectationsForRunnable('afterEach spec', [msg]);
1984
-
1985
- done();
1986
- });
1987
-
1988
- env.addReporter(reporter);
1989
-
1990
- env.describe('suite', function() {
1991
- env.it('describe', function() { env.describe('inner suite', function() {}); });
1992
- env.it('xdescribe', function() { env.xdescribe('inner suite', function() {}); });
1993
- env.it('fdescribe', function() { env.fdescribe('inner suite', function() {}); });
1994
- });
1995
-
1996
- env.describe('spec', function() {
1997
- env.it('it', function() { env.it('inner spec', function() {}); });
1998
- env.it('xit', function() { env.xit('inner spec', function() {}); });
1999
- env.it('fit', function() { env.fit('inner spec', function() {}); });
2000
- });
2001
-
2002
- env.describe('beforeAll', function() {
2003
- env.beforeAll(function() { env.beforeAll(function() {}); });
2004
- env.it('spec', function() {});
2005
- });
2006
-
2007
- env.describe('beforeEach', function() {
2008
- env.beforeEach(function() { env.beforeEach(function() {}); });
2009
- env.it('spec', function() {});
2010
- });
2011
-
2012
- env.describe('afterAll', function() {
2013
- env.afterAll(function() { env.afterAll(function() {}); });
2014
- env.it('spec', function() {});
2015
- });
2016
-
2017
- env.describe('afterEach', function() {
2018
- env.afterEach(function() { env.afterEach(function() {}); });
2019
- env.it('spec', function() {});
2020
- });
2021
-
2022
- env.execute();
2023
- });
2024
-
2025
- it('reports errors that occur during loading', function(done) {
2026
- var global = {
2027
- setTimeout: function(fn, delay) { setTimeout(fn, delay) },
2028
- clearTimeout: function(fn, delay) { clearTimeout(fn, delay) },
2029
- };
2030
- spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
2031
-
2032
- var env = new jasmineUnderTest.Env(),
2033
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2034
-
2035
- reporter.jasmineDone.and.callFake(function(e) {
2036
- expect(e.failedExpectations).toEqual([
2037
- {
2038
- passed: false,
2039
- globalErrorType: 'load',
2040
- message: 'Uncaught SyntaxError: Unexpected end of input',
2041
- filename: 'borkenSpec.js',
2042
- lineno: 42
2043
- },
2044
- {
2045
- passed: false,
2046
- globalErrorType: 'load',
2047
- message: 'Uncaught Error: ENOCHEESE',
2048
- filename: undefined,
2049
- lineno: undefined
2050
- }
2051
- ]);
2052
-
2053
- done();
2054
- });
2055
-
2056
- env.addReporter(reporter);
2057
- global.onerror('Uncaught SyntaxError: Unexpected end of input', 'borkenSpec.js', 42);
2058
- global.onerror('Uncaught Error: ENOCHEESE');
2059
-
2060
- env.execute();
2061
- });
2062
-
2063
- describe('If suppressLoadErrors was called', function() {
2064
- it('does not report or handle errors that occur during loading', function(done) {
2065
- var global = {
2066
- setTimeout: function(fn, delay) { setTimeout(fn, delay) },
2067
- clearTimeout: function(fn, delay) { clearTimeout(fn, delay) }
2068
- };
2069
- spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
2070
- var globalErrors = new jasmineUnderTest.GlobalErrors(global);
2071
- var onerror = jasmine.createSpy('onerror');
2072
- globalErrors.pushListener(onerror);
2073
- spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
2074
-
2075
- var env = new jasmineUnderTest.Env(),
2076
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2077
-
2078
- reporter.jasmineDone.and.callFake(function(e) {
2079
- expect(e.failedExpectations).toEqual([]);
2080
- expect(onerror).toHaveBeenCalledWith('Uncaught Error: ENOCHEESE');
2081
- done();
2082
- });
2083
-
2084
- env.addReporter(reporter);
2085
- env.suppressLoadErrors(true);
2086
- global.onerror('Uncaught Error: ENOCHEESE');
2087
-
2088
- env.execute();
2089
- });
2090
- });
2091
-
2092
- describe('Overall status in the jasmineDone event', function() {
2093
- describe('When everything passes', function() {
2094
- it('is "passed"', function(done) {
2095
- var env = new jasmineUnderTest.Env(),
2096
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2097
-
2098
- reporter.jasmineDone.and.callFake(function(e) {
2099
- expect(e.overallStatus).toEqual('passed');
2100
- done();
2101
- });
2102
-
2103
- env.addReporter(reporter);
2104
- env.it('passes', function() {});
2105
- env.execute();
2106
- });
2107
- });
2108
-
2109
- describe('When a spec fails', function() {
2110
- it('is "failed"', function(done) {
2111
- var env = new jasmineUnderTest.Env(),
2112
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2113
-
2114
- reporter.jasmineDone.and.callFake(function(e) {
2115
- expect(e.overallStatus).toEqual('failed');
2116
- done();
2117
- });
2118
-
2119
- env.addReporter(reporter);
2120
- env.it('fails', function() {
2121
- env.expect(true).toBe(false);
2122
- });
2123
- env.execute();
2124
- });
2125
- });
2126
-
2127
- describe('When a top-level beforeAll fails', function() {
2128
- it('is "failed"', function(done) {
2129
- var env = new jasmineUnderTest.Env(),
2130
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2131
-
2132
- reporter.jasmineDone.and.callFake(function(e) {
2133
- expect(e.overallStatus).toEqual('failed');
2134
- done();
2135
- });
2136
-
2137
- env.addReporter(reporter);
2138
- env.beforeAll(function() {
2139
- throw new Error('nope');
2140
- });
2141
- env.it('does not run', function() {});
2142
- env.execute();
2143
- });
2144
- });
2145
-
2146
- describe('When a suite beforeAll fails', function() {
2147
- it('is "failed"', function(done) {
2148
- var env = new jasmineUnderTest.Env(),
2149
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2150
-
2151
- reporter.jasmineDone.and.callFake(function(e) {
2152
- expect(e.overallStatus).toEqual('failed');
2153
- done();
2154
- });
2155
-
2156
- env.addReporter(reporter);
2157
- env.describe('something', function() {
2158
- env.beforeAll(function() {
2159
- throw new Error('nope');
2160
- });
2161
- env.it('does not run', function() {});
2162
- });
2163
- env.execute();
2164
- });
2165
- });
2166
-
2167
- describe('When a top-level afterAll fails', function() {
2168
- it('is "failed"', function(done) {
2169
- var env = new jasmineUnderTest.Env(),
2170
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2171
-
2172
- reporter.jasmineDone.and.callFake(function(e) {
2173
- expect(e.overallStatus).toEqual('failed');
2174
- done();
2175
- });
2176
-
2177
- env.addReporter(reporter);
2178
- env.afterAll(function() {
2179
- throw new Error('nope');
2180
- });
2181
- env.it('does not run', function() {});
2182
- env.execute();
2183
- });
2184
- });
2185
-
2186
- describe('When a suite afterAll fails', function() {
2187
- it('is "failed"', function(done) {
2188
- var env = new jasmineUnderTest.Env(),
2189
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2190
-
2191
- reporter.jasmineDone.and.callFake(function(e) {
2192
- expect(e.overallStatus).toEqual('failed');
2193
- done();
2194
- });
2195
-
2196
- env.addReporter(reporter);
2197
- env.describe('something', function() {
2198
- env.afterAll(function() {
2199
- throw new Error('nope');
2200
- });
2201
- env.it('does not run', function() {});
2202
- });
2203
- env.execute();
2204
- });
2205
- });
2206
-
2207
- describe("When there are load errors", function() {
2208
- it('is "failed"', function(done) {
2209
- var global = {
2210
- setTimeout: function(fn, delay) { setTimeout(fn, delay) },
2211
- clearTimeout: function(fn, delay) { clearTimeout(fn, delay) },
2212
- };
2213
- spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
2214
-
2215
- var env = new jasmineUnderTest.Env();
2216
- var reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2217
-
2218
- reporter.jasmineDone.and.callFake(function(e) {
2219
- expect(e.overallStatus).toEqual('failed');
2220
- done();
2221
- });
2222
-
2223
- env.addReporter(reporter);
2224
- env.it('passes', function() {});
2225
- global.onerror('Uncaught Error: ENOCHEESE');
2226
- env.execute();
2227
- });
2228
- });
2229
-
2230
- describe('When there are no specs', function() {
2231
- it('is "incomplete"', function(done) {
2232
- var env = new jasmineUnderTest.Env(),
2233
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2234
-
2235
- reporter.jasmineDone.and.callFake(function(e) {
2236
- expect(e.overallStatus).toEqual('incomplete');
2237
- expect(e.incompleteReason).toEqual('No specs found');
2238
- done();
2239
- });
2240
-
2241
- env.addReporter(reporter);
2242
- env.execute();
2243
- });
2244
- });
2245
-
2246
- describe('When a spec is focused', function() {
2247
- it('is "incomplete"', function(done) {
2248
- var env = new jasmineUnderTest.Env(),
2249
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2250
-
2251
- reporter.jasmineDone.and.callFake(function(e) {
2252
- expect(e.overallStatus).toEqual('incomplete');
2253
- expect(e.incompleteReason).toEqual('fit() or fdescribe() was found');
2254
- done();
2255
- });
2256
-
2257
- env.addReporter(reporter);
2258
- env.fit('is focused', function() {});
2259
- env.execute();
2260
- });
2261
- });
2262
-
2263
- describe('When a suite is focused', function() {
2264
- it('is "incomplete"', function(done) {
2265
- var env = new jasmineUnderTest.Env(),
2266
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2267
-
2268
- reporter.jasmineDone.and.callFake(function(e) {
2269
- expect(e.overallStatus).toEqual('incomplete');
2270
- expect(e.incompleteReason).toEqual('fit() or fdescribe() was found');
2271
- done();
2272
- });
2273
-
2274
- env.addReporter(reporter);
2275
- env.fdescribe('something focused', function() {
2276
- env.it('does a thing', function() {});
2277
- });
2278
- env.execute();
2279
- });
2280
- });
2281
-
2282
- describe('When there are both failures and focused specs', function() {
2283
- it('is "failed"', function(done) {
2284
- var env = new jasmineUnderTest.Env(),
2285
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2286
-
2287
- reporter.jasmineDone.and.callFake(function(e) {
2288
- expect(e.overallStatus).toEqual('failed');
2289
- expect(e.incompleteReason).toBeUndefined();
2290
- done();
2291
- });
2292
-
2293
- env.addReporter(reporter);
2294
- env.fit('is focused', function() {
2295
- env.expect(true).toBe(false);
2296
- });
2297
- env.execute();
2298
- });
2299
- });
2300
- });
2301
-
2302
- it('should report deprecation warnings on the correct specs and suites', function(done) {
2303
- var env = new jasmineUnderTest.Env(),
2304
- reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
2305
-
2306
- reporter.jasmineDone.and.callFake(function(result) {
2307
- expect(result.deprecationWarnings).toEqual([
2308
- jasmine.objectContaining({ message: 'top level deprecation' })
2309
- ]);
2310
-
2311
- expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
2312
- fullName: 'suite',
2313
- deprecationWarnings: [
2314
- jasmine.objectContaining({ message: 'suite level deprecation' })
2315
- ]
2316
- }));
2317
-
2318
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
2319
- fullName: 'suite spec',
2320
- deprecationWarnings: [
2321
- jasmine.objectContaining({ message: 'spec level deprecation' })
2322
- ]
2323
- }));
2324
-
2325
- done();
2326
- });
2327
-
2328
- env.addReporter(reporter);
2329
-
2330
- env.deprecated('top level deprecation');
2331
-
2332
- env.describe('suite', function() {
2333
- env.beforeAll(function() {
2334
- env.deprecated('suite level deprecation');
2335
- });
2336
-
2337
- env.it('spec', function() {
2338
- env.deprecated('spec level deprecation');
2339
- });
2340
- });
2341
-
2342
- env.execute();
2343
- });
2344
- });