jasmine-core 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/console/console.js +54 -24
- data/lib/jasmine-core/__init__.py +1 -0
- data/lib/jasmine-core/boot/boot.js +2 -63
- data/lib/jasmine-core/boot/node_boot.js +19 -0
- data/lib/jasmine-core/boot.js +3 -64
- data/lib/jasmine-core/core.py +60 -0
- data/lib/jasmine-core/example/node_example/spec/PlayerSpec.js +60 -0
- data/lib/jasmine-core/example/node_example/spec/SpecHelper.js +15 -0
- data/lib/jasmine-core/example/node_example/src/Player.js +24 -0
- data/lib/jasmine-core/example/node_example/src/Song.js +9 -0
- data/lib/jasmine-core/jasmine-html.js +119 -74
- data/lib/jasmine-core/jasmine.css +61 -54
- data/lib/jasmine-core/jasmine.js +964 -456
- data/lib/jasmine-core/json2.js +73 -62
- data/lib/jasmine-core/node_boot.js +41 -0
- data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +52 -8
- data/lib/jasmine-core/spec/core/AnySpec.js +1 -0
- data/lib/jasmine-core/spec/core/ClockSpec.js +122 -18
- data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +14 -1
- data/lib/jasmine-core/spec/core/EnvSpec.js +0 -63
- data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +7 -0
- data/lib/jasmine-core/spec/core/ExceptionsSpec.js +2 -2
- data/lib/jasmine-core/spec/core/ExpectationSpec.js +46 -50
- data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +37 -0
- data/lib/jasmine-core/spec/core/MockDateSpec.js +200 -0
- data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +6 -0
- data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +49 -12
- data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +184 -60
- data/lib/jasmine-core/spec/core/SpecSpec.js +46 -108
- data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +55 -0
- data/lib/jasmine-core/spec/core/SpySpec.js +10 -0
- data/lib/jasmine-core/spec/core/SpyStrategySpec.js +13 -0
- data/lib/jasmine-core/spec/core/SuiteSpec.js +143 -11
- data/lib/jasmine-core/spec/core/TimerSpec.js +18 -0
- data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +34 -32
- data/lib/jasmine-core/spec/core/integration/EnvSpec.js +998 -50
- data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +279 -3
- data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +18 -1
- data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +2 -1
- data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +3 -2
- data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +2 -1
- data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +4 -2
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +2 -1
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +17 -3
- data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +14 -14
- data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +5 -5
- data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +7 -0
- data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +33 -0
- data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +183 -35
- data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +1 -1
- data/lib/jasmine-core/spec/node_suite.js +9 -1
- data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +104 -0
- data/lib/jasmine-core/spec/performance/large_object_test.js +36 -0
- data/lib/jasmine-core/version.rb +1 -1
- data/lib/jasmine-core.js +37 -0
- data/lib/jasmine-core.rb +6 -2
- metadata +23 -9
- data/lib/jasmine-core/spec/support/dev_boot.js +0 -124
@@ -14,18 +14,22 @@ describe("Spec", function() {
|
|
14
14
|
expect(j$.Spec.isPendingSpecException(fakeError)).toBe(true);
|
15
15
|
});
|
16
16
|
|
17
|
-
it("#isPendingSpecException returns
|
17
|
+
it("#isPendingSpecException returns false for not a pending spec exception", function() {
|
18
18
|
var e = new Error("foo");
|
19
19
|
|
20
20
|
expect(j$.Spec.isPendingSpecException(e)).toBe(false);
|
21
21
|
});
|
22
22
|
|
23
|
+
it("#isPendingSpecException returns false for thrown values that don't have toString", function() {
|
24
|
+
expect(j$.Spec.isPendingSpecException(void 0)).toBe(false);
|
25
|
+
});
|
26
|
+
|
23
27
|
it("delegates execution to a QueueRunner", function() {
|
24
28
|
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
25
29
|
spec = new j$.Spec({
|
26
30
|
description: 'my test',
|
27
31
|
id: 'some-id',
|
28
|
-
fn: function() {},
|
32
|
+
queueableFn: { fn: function() {} },
|
29
33
|
queueRunnerFactory: fakeQueueRunner
|
30
34
|
});
|
31
35
|
|
@@ -40,7 +44,7 @@ describe("Spec", function() {
|
|
40
44
|
spec = new j$.Spec({
|
41
45
|
id: 123,
|
42
46
|
description: 'foo bar',
|
43
|
-
fn: function() {},
|
47
|
+
queueableFn: { fn: function() {} },
|
44
48
|
onStart: startCallback,
|
45
49
|
queueRunnerFactory: fakeQueueRunner
|
46
50
|
});
|
@@ -62,7 +66,7 @@ describe("Spec", function() {
|
|
62
66
|
expect(beforesWereCalled).toBe(false);
|
63
67
|
}),
|
64
68
|
spec = new j$.Spec({
|
65
|
-
fn: function() {},
|
69
|
+
queueableFn: { fn: function() {} },
|
66
70
|
beforeFns: function() {
|
67
71
|
return [function() {
|
68
72
|
beforesWereCalled = true
|
@@ -81,25 +85,22 @@ describe("Spec", function() {
|
|
81
85
|
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
82
86
|
before = jasmine.createSpy('before'),
|
83
87
|
after = jasmine.createSpy('after'),
|
84
|
-
|
88
|
+
queueableFn = { fn: jasmine.createSpy('test body').and.callFake(function() {
|
85
89
|
expect(before).toHaveBeenCalled();
|
86
90
|
expect(after).not.toHaveBeenCalled();
|
87
|
-
}),
|
91
|
+
}) },
|
88
92
|
spec = new j$.Spec({
|
89
|
-
|
90
|
-
|
91
|
-
return [before]
|
92
|
-
},
|
93
|
-
afterFns: function() {
|
94
|
-
return [after]
|
93
|
+
queueableFn: queueableFn,
|
94
|
+
beforeAndAfterFns: function() {
|
95
|
+
return {befores: [before], afters: [after]}
|
95
96
|
},
|
96
97
|
queueRunnerFactory: fakeQueueRunner
|
97
98
|
});
|
98
99
|
|
99
100
|
spec.execute();
|
100
101
|
|
101
|
-
var allSpecFns = fakeQueueRunner.calls.mostRecent().args[0].
|
102
|
-
expect(allSpecFns).toEqual([before,
|
102
|
+
var allSpecFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
103
|
+
expect(allSpecFns).toEqual([before, queueableFn, after]);
|
103
104
|
});
|
104
105
|
|
105
106
|
it("is marked pending if created without a function body", function() {
|
@@ -109,7 +110,7 @@ describe("Spec", function() {
|
|
109
110
|
resultCallback = jasmine.createSpy('resultCallback'),
|
110
111
|
spec = new j$.Spec({
|
111
112
|
onStart: startCallback,
|
112
|
-
fn: null,
|
113
|
+
queueableFn: { fn: null },
|
113
114
|
resultCallback: resultCallback,
|
114
115
|
queueRunnerFactory: fakeQueueRunner
|
115
116
|
});
|
@@ -125,7 +126,7 @@ describe("Spec", function() {
|
|
125
126
|
resultCallback = jasmine.createSpy('resultCallback'),
|
126
127
|
spec = new j$.Spec({
|
127
128
|
onStart:startCallback,
|
128
|
-
fn: specBody,
|
129
|
+
queueableFn: { fn: specBody },
|
129
130
|
resultCallback: resultCallback,
|
130
131
|
queueRunnerFactory: fakeQueueRunner
|
131
132
|
});
|
@@ -154,7 +155,8 @@ describe("Spec", function() {
|
|
154
155
|
getSpecName: function() {
|
155
156
|
return "a suite with a spec"
|
156
157
|
},
|
157
|
-
queueRunnerFactory: fakeQueueRunner
|
158
|
+
queueRunnerFactory: fakeQueueRunner,
|
159
|
+
queueableFn: { fn: null }
|
158
160
|
});
|
159
161
|
|
160
162
|
spec.pend();
|
@@ -171,14 +173,15 @@ describe("Spec", function() {
|
|
171
173
|
status: 'pending',
|
172
174
|
description: 'with a spec',
|
173
175
|
fullName: 'a suite with a spec',
|
174
|
-
failedExpectations: []
|
176
|
+
failedExpectations: [],
|
177
|
+
passedExpectations: []
|
175
178
|
});
|
176
179
|
});
|
177
180
|
|
178
181
|
it("should call the done callback on execution complete", function() {
|
179
182
|
var done = jasmine.createSpy('done callback'),
|
180
183
|
spec = new j$.Spec({
|
181
|
-
fn: function() {},
|
184
|
+
queueableFn: { fn: function() {} },
|
182
185
|
catchExceptions: function() { return false; },
|
183
186
|
resultCallback: function() {},
|
184
187
|
queueRunnerFactory: function(attrs) { attrs.onComplete(); }
|
@@ -190,118 +193,53 @@ describe("Spec", function() {
|
|
190
193
|
});
|
191
194
|
|
192
195
|
it("#status returns passing by default", function() {
|
193
|
-
var spec = new j$.Spec({fn: jasmine.createSpy("spec body")});
|
194
|
-
expect(spec.status()).
|
196
|
+
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
|
197
|
+
expect(spec.status()).toBe('passed');
|
195
198
|
});
|
196
199
|
|
197
200
|
it("#status returns passed if all expectations in the spec have passed", function() {
|
198
|
-
var spec = new j$.Spec({fn: jasmine.createSpy("spec body")});
|
201
|
+
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
|
199
202
|
spec.addExpectationResult(true);
|
200
203
|
expect(spec.status()).toBe('passed');
|
201
204
|
});
|
202
205
|
|
203
206
|
it("#status returns failed if any expectations in the spec have failed", function() {
|
204
|
-
var spec = new j$.Spec({ fn: jasmine.createSpy("spec body") });
|
207
|
+
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body") } });
|
205
208
|
spec.addExpectationResult(true);
|
206
209
|
spec.addExpectationResult(false);
|
207
210
|
expect(spec.status()).toBe('failed');
|
208
211
|
});
|
209
212
|
|
210
|
-
it("
|
211
|
-
var
|
212
|
-
|
213
|
-
var spec = new j$.Spec({
|
214
|
-
getSpecName: specNameSpy
|
215
|
-
});
|
216
|
-
|
217
|
-
expect(spec.getFullName()).toBe('expected val');
|
218
|
-
expect(specNameSpy.calls.mostRecent().args[0].id).toEqual(spec.id);
|
219
|
-
});
|
220
|
-
|
221
|
-
it("sets a timeout for async functions to keep them from running forever", function() {
|
222
|
-
var queueRunnerSpy = jasmine.createSpy('queue runner'),
|
223
|
-
setTimeoutSpy = jasmine.createSpy('setTimeout'),
|
213
|
+
it("keeps track of passed and failed expectations", function() {
|
214
|
+
var resultCallback = jasmine.createSpy('resultCallback'),
|
224
215
|
spec = new j$.Spec({
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
setTimeout: setTimeoutSpy,
|
230
|
-
clearTimeout: function() {}
|
231
|
-
},
|
232
|
-
queueRunnerFactory: queueRunnerSpy
|
216
|
+
queueableFn: { fn: jasmine.createSpy("spec body") },
|
217
|
+
expectationResultFactory: function (data) { return data; },
|
218
|
+
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
|
219
|
+
resultCallback: resultCallback
|
233
220
|
});
|
221
|
+
spec.addExpectationResult(true, 'expectation1');
|
222
|
+
spec.addExpectationResult(false, 'expectation2');
|
234
223
|
|
235
224
|
spec.execute();
|
236
|
-
var fns = queueRunnerSpy.calls.mostRecent().args[0].fns;
|
237
|
-
|
238
|
-
for (var i = 0; i < fns.length; i++) {
|
239
|
-
fns[i]();
|
240
|
-
}
|
241
225
|
|
242
|
-
expect(
|
243
|
-
expect(
|
226
|
+
expect(resultCallback.calls.first().args[0].passedExpectations).toEqual(['expectation1']);
|
227
|
+
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual(['expectation2']);
|
244
228
|
});
|
245
229
|
|
246
|
-
it("
|
247
|
-
var
|
248
|
-
clearTimeoutSpy = jasmine.createSpy('clear timeout'),
|
249
|
-
spec = new j$.Spec({
|
250
|
-
beforeFns: function() { return [function(done) {}]; },
|
251
|
-
fn: function() { },
|
252
|
-
timer: {
|
253
|
-
setTimeout: function () { return 920; },
|
254
|
-
clearTimeout: clearTimeoutSpy
|
255
|
-
},
|
256
|
-
queueRunnerFactory: queueRunnerSpy
|
257
|
-
});
|
258
|
-
|
259
|
-
spec.execute();
|
260
|
-
queueRunnerSpy.calls.mostRecent().args[0].fns[0]();
|
261
|
-
queueRunnerSpy.calls.mostRecent().args[0].onException(new Error());
|
262
|
-
|
263
|
-
expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
|
264
|
-
});
|
265
|
-
|
266
|
-
it("resets the timeout timer when an async spec throws an exception", function() {
|
267
|
-
var queueRunnerSpy = jasmine.createSpy('queueRunner'),
|
268
|
-
clearTimeoutSpy = jasmine.createSpy('clear timeout'),
|
269
|
-
spec = new j$.Spec({
|
270
|
-
fn: function(done) { },
|
271
|
-
timer: {
|
272
|
-
setTimeout: function () { return 920; },
|
273
|
-
clearTimeout: clearTimeoutSpy
|
274
|
-
},
|
275
|
-
queueRunnerFactory: queueRunnerSpy
|
276
|
-
});
|
230
|
+
it("can return its full name", function() {
|
231
|
+
var specNameSpy = jasmine.createSpy('specNameSpy').and.returnValue('expected val');
|
277
232
|
|
278
|
-
spec
|
279
|
-
|
280
|
-
|
233
|
+
var spec = new j$.Spec({
|
234
|
+
getSpecName: specNameSpy,
|
235
|
+
queueableFn: { fn: null }
|
236
|
+
});
|
281
237
|
|
282
|
-
expect(
|
238
|
+
expect(spec.getFullName()).toBe('expected val');
|
239
|
+
expect(specNameSpy.calls.mostRecent().args[0].id).toEqual(spec.id);
|
283
240
|
});
|
284
241
|
|
285
|
-
|
286
|
-
var queueRunnerSpy = jasmine.createSpy('queueRunner'),
|
287
|
-
clearTimeoutSpy = jasmine.createSpy('clear timeout'),
|
288
|
-
spec = new j$.Spec({
|
289
|
-
fn: function() { },
|
290
|
-
afterFns: function() { return [function(done) {}]; },
|
291
|
-
timer: {
|
292
|
-
setTimeout: function () { return 920; },
|
293
|
-
clearTimeout: clearTimeoutSpy
|
294
|
-
},
|
295
|
-
queueRunnerFactory: queueRunnerSpy
|
296
|
-
});
|
297
|
-
|
298
|
-
spec.execute();
|
299
|
-
queueRunnerSpy.calls.mostRecent().args[0].fns[1]();
|
300
|
-
queueRunnerSpy.calls.mostRecent().args[0].onException(new Error());
|
301
|
-
|
302
|
-
expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
|
303
|
-
});
|
304
|
-
describe("when a spec is marked pending during execution", function() {
|
242
|
+
describe("when a spec is marked pending during execution", function() {
|
305
243
|
it("should mark the spec as pending", function() {
|
306
244
|
var fakeQueueRunner = function(opts) {
|
307
245
|
opts.onException(new Error(j$.Spec.pendingSpecExceptionMessage));
|
@@ -309,7 +247,7 @@ describe("Spec", function() {
|
|
309
247
|
spec = new j$.Spec({
|
310
248
|
description: 'my test',
|
311
249
|
id: 'some-id',
|
312
|
-
fn: function() { },
|
250
|
+
queueableFn: { fn: function() { } },
|
313
251
|
queueRunnerFactory: fakeQueueRunner
|
314
252
|
});
|
315
253
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
describe("SpyRegistry", function() {
|
2
|
+
describe("#spyOn", function() {
|
3
|
+
it("checks for the existence of the object", function() {
|
4
|
+
var spyRegistry = new j$.SpyRegistry();
|
5
|
+
expect(function() {
|
6
|
+
spyRegistry.spyOn(void 0, 'pants');
|
7
|
+
}).toThrowError(/could not find an object/);
|
8
|
+
});
|
9
|
+
|
10
|
+
it("checks for the existence of the method", function() {
|
11
|
+
var spyRegistry = new j$.SpyRegistry(),
|
12
|
+
subject = {};
|
13
|
+
|
14
|
+
expect(function() {
|
15
|
+
spyRegistry.spyOn(subject, 'pants');
|
16
|
+
}).toThrowError(/method does not exist/);
|
17
|
+
});
|
18
|
+
|
19
|
+
it("checks if it has already been spied upon", function() {
|
20
|
+
var spies = [],
|
21
|
+
spyRegistry = new j$.SpyRegistry({currentSpies: function() { return spies; }}),
|
22
|
+
subject = { spiedFunc: function() {} };
|
23
|
+
|
24
|
+
spyRegistry.spyOn(subject, 'spiedFunc');
|
25
|
+
|
26
|
+
expect(function() {
|
27
|
+
spyRegistry.spyOn(subject, 'spiedFunc');
|
28
|
+
}).toThrowError(/has already been spied upon/);
|
29
|
+
});
|
30
|
+
|
31
|
+
it("overrides the method on the object and returns the spy", function() {
|
32
|
+
var originalFunctionWasCalled = false,
|
33
|
+
spyRegistry = new j$.SpyRegistry(),
|
34
|
+
subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
|
35
|
+
|
36
|
+
var spy = spyRegistry.spyOn(subject, 'spiedFunc');
|
37
|
+
|
38
|
+
expect(subject.spiedFunc).toEqual(spy);
|
39
|
+
});
|
40
|
+
});
|
41
|
+
|
42
|
+
describe("#clearSpies", function() {
|
43
|
+
it("restores the original functions on the spied-upon objects", function() {
|
44
|
+
var spies = [],
|
45
|
+
spyRegistry = new j$.SpyRegistry({currentSpies: function() { return spies; }}),
|
46
|
+
originalFunction = function() {},
|
47
|
+
subject = { spiedFunc: originalFunction };
|
48
|
+
|
49
|
+
spyRegistry.spyOn(subject, 'spiedFunc');
|
50
|
+
spyRegistry.clearSpies();
|
51
|
+
|
52
|
+
expect(subject.spiedFunc).toBe(originalFunction);
|
53
|
+
});
|
54
|
+
});
|
55
|
+
});
|
@@ -47,6 +47,16 @@ describe('Spies', function () {
|
|
47
47
|
|
48
48
|
expect(trackSpy.calls.mostRecent().args[0].object).toEqual(contextObject);
|
49
49
|
});
|
50
|
+
|
51
|
+
it("tracks the return value of calls", function () {
|
52
|
+
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
|
53
|
+
var trackSpy = spyOn(spy.calls, "track");
|
54
|
+
|
55
|
+
spy.and.returnValue("return value");
|
56
|
+
spy();
|
57
|
+
|
58
|
+
expect(trackSpy.calls.mostRecent().args[0].returnValue).toEqual("return value");
|
59
|
+
});
|
50
60
|
});
|
51
61
|
|
52
62
|
describe("createSpyObj", function() {
|
@@ -46,6 +46,19 @@ describe("SpyStrategy", function() {
|
|
46
46
|
expect(returnValue).toEqual(17);
|
47
47
|
});
|
48
48
|
|
49
|
+
it("can return specified values in order specified when executed", function() {
|
50
|
+
var originalFn = jasmine.createSpy("original"),
|
51
|
+
spyStrategy = new j$.SpyStrategy({fn: originalFn});
|
52
|
+
|
53
|
+
spyStrategy.returnValues('value1', 'value2', 'value3');
|
54
|
+
|
55
|
+
expect(spyStrategy.exec()).toEqual('value1');
|
56
|
+
expect(spyStrategy.exec()).toEqual('value2');
|
57
|
+
expect(spyStrategy.exec()).toBe('value3');
|
58
|
+
expect(spyStrategy.exec()).toBeUndefined();
|
59
|
+
expect(originalFn).not.toHaveBeenCalled();
|
60
|
+
});
|
61
|
+
|
49
62
|
it("allows an exception to be thrown when executed", function() {
|
50
63
|
var originalFn = jasmine.createSpy("original"),
|
51
64
|
spyStrategy = new j$.SpyStrategy({fn: originalFn});
|
@@ -52,6 +52,31 @@ describe("Suite", function() {
|
|
52
52
|
expect(suite.beforeFns).toEqual([innerBefore, outerBefore]);
|
53
53
|
});
|
54
54
|
|
55
|
+
it("runs beforeAll functions in order of needed execution", function() {
|
56
|
+
var env = new j$.Env(),
|
57
|
+
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
|
58
|
+
suite = new j$.Suite({
|
59
|
+
env: env,
|
60
|
+
description: "I am a suite",
|
61
|
+
queueRunner: fakeQueueRunner
|
62
|
+
}),
|
63
|
+
firstBefore = jasmine.createSpy('outerBeforeAll'),
|
64
|
+
lastBefore = jasmine.createSpy('insideBeforeAll'),
|
65
|
+
fakeIt = {execute: jasmine.createSpy('it'), isExecutable: function() { return true; } };
|
66
|
+
|
67
|
+
suite.beforeAll(firstBefore);
|
68
|
+
suite.beforeAll(lastBefore);
|
69
|
+
suite.addChild(fakeIt);
|
70
|
+
|
71
|
+
suite.execute();
|
72
|
+
var suiteFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
73
|
+
|
74
|
+
suiteFns[0]();
|
75
|
+
expect(firstBefore).toHaveBeenCalled();
|
76
|
+
suiteFns[1]();
|
77
|
+
expect(lastBefore).toHaveBeenCalled();
|
78
|
+
});
|
79
|
+
|
55
80
|
it("adds after functions in order of needed execution", function() {
|
56
81
|
var env = new j$.Env(),
|
57
82
|
suite = new j$.Suite({
|
@@ -67,12 +92,42 @@ describe("Suite", function() {
|
|
67
92
|
expect(suite.afterFns).toEqual([innerAfter, outerAfter]);
|
68
93
|
});
|
69
94
|
|
70
|
-
it("
|
95
|
+
it("runs afterAll functions in order of needed execution", function() {
|
96
|
+
var env = new j$.Env(),
|
97
|
+
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
|
98
|
+
suite = new j$.Suite({
|
99
|
+
env: env,
|
100
|
+
description: "I am a suite",
|
101
|
+
queueRunner: fakeQueueRunner
|
102
|
+
}),
|
103
|
+
firstAfter = jasmine.createSpy('outerAfterAll'),
|
104
|
+
lastAfter = jasmine.createSpy('insideAfterAll'),
|
105
|
+
fakeIt = {execute: jasmine.createSpy('it'), isExecutable: function() { return true; } };
|
106
|
+
|
107
|
+
suite.afterAll(firstAfter);
|
108
|
+
suite.afterAll(lastAfter);
|
109
|
+
suite.addChild(fakeIt);
|
110
|
+
|
111
|
+
suite.execute();
|
112
|
+
var suiteFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
|
113
|
+
|
114
|
+
suiteFns[1]();
|
115
|
+
expect(firstAfter).toHaveBeenCalled();
|
116
|
+
suiteFns[2]();
|
117
|
+
expect(lastAfter).toHaveBeenCalled();
|
118
|
+
});
|
119
|
+
|
120
|
+
it("can be disabled, but still calls callbacks", function() {
|
71
121
|
var env = new j$.Env(),
|
72
122
|
fakeQueueRunner = jasmine.createSpy('fake queue runner'),
|
123
|
+
onStart = jasmine.createSpy('onStart'),
|
124
|
+
resultCallback = jasmine.createSpy('resultCallback'),
|
125
|
+
onComplete = jasmine.createSpy('onComplete'),
|
73
126
|
suite = new j$.Suite({
|
74
127
|
env: env,
|
75
128
|
description: "with a child suite",
|
129
|
+
onStart: onStart,
|
130
|
+
resultCallback: resultCallback,
|
76
131
|
queueRunner: fakeQueueRunner
|
77
132
|
});
|
78
133
|
|
@@ -80,12 +135,15 @@ describe("Suite", function() {
|
|
80
135
|
|
81
136
|
expect(suite.disabled).toBe(true);
|
82
137
|
|
83
|
-
suite.execute();
|
138
|
+
suite.execute(onComplete);
|
84
139
|
|
85
140
|
expect(fakeQueueRunner).not.toHaveBeenCalled();
|
141
|
+
expect(onStart).toHaveBeenCalled();
|
142
|
+
expect(resultCallback).toHaveBeenCalled();
|
143
|
+
expect(onComplete).toHaveBeenCalled();
|
86
144
|
});
|
87
145
|
|
88
|
-
it("delegates execution of its specs and
|
146
|
+
it("delegates execution of its specs, suites, beforeAlls, and afterAlls", function() {
|
89
147
|
var env = new j$.Env(),
|
90
148
|
parentSuiteDone = jasmine.createSpy('parent suite done'),
|
91
149
|
fakeQueueRunnerForParent = jasmine.createSpy('fake parent queue runner'),
|
@@ -101,22 +159,57 @@ describe("Suite", function() {
|
|
101
159
|
queueRunner: fakeQueueRunner
|
102
160
|
}),
|
103
161
|
fakeSpec1 = {
|
104
|
-
execute: jasmine.createSpy('fakeSpec1')
|
105
|
-
|
162
|
+
execute: jasmine.createSpy('fakeSpec1'),
|
163
|
+
isExecutable: function() { return true; }
|
164
|
+
},
|
165
|
+
beforeAllFn = { fn: jasmine.createSpy('beforeAll') },
|
166
|
+
afterAllFn = { fn: jasmine.createSpy('afterAll') };
|
106
167
|
|
107
168
|
spyOn(suite, "execute");
|
108
169
|
|
109
170
|
parentSuite.addChild(fakeSpec1);
|
110
171
|
parentSuite.addChild(suite);
|
172
|
+
parentSuite.beforeAll(beforeAllFn);
|
173
|
+
parentSuite.afterAll(afterAllFn);
|
111
174
|
|
112
175
|
parentSuite.execute(parentSuiteDone);
|
113
176
|
|
114
|
-
var parentSuiteFns = fakeQueueRunnerForParent.calls.mostRecent().args[0].
|
177
|
+
var parentSuiteFns = fakeQueueRunnerForParent.calls.mostRecent().args[0].queueableFns;
|
115
178
|
|
116
|
-
parentSuiteFns[0]();
|
179
|
+
parentSuiteFns[0].fn();
|
180
|
+
expect(beforeAllFn.fn).toHaveBeenCalled();
|
181
|
+
parentSuiteFns[1].fn();
|
117
182
|
expect(fakeSpec1.execute).toHaveBeenCalled();
|
118
|
-
parentSuiteFns[
|
183
|
+
parentSuiteFns[2].fn();
|
119
184
|
expect(suite.execute).toHaveBeenCalled();
|
185
|
+
parentSuiteFns[3].fn();
|
186
|
+
expect(afterAllFn.fn).toHaveBeenCalled();
|
187
|
+
});
|
188
|
+
|
189
|
+
it("does not run beforeAll or afterAll if there are no child specs to run", function() {
|
190
|
+
var env = new j$.Env(),
|
191
|
+
fakeQueueRunnerForParent = jasmine.createSpy('fake parent queue runner'),
|
192
|
+
fakeQueueRunnerForChild = jasmine.createSpy('fake child queue runner'),
|
193
|
+
parentSuite = new j$.Suite({
|
194
|
+
env: env,
|
195
|
+
description: "I am a suite",
|
196
|
+
queueRunner: fakeQueueRunnerForParent
|
197
|
+
}),
|
198
|
+
childSuite = new j$.Suite({
|
199
|
+
env: env,
|
200
|
+
description: "I am a suite",
|
201
|
+
queueRunner: fakeQueueRunnerForChild,
|
202
|
+
parentSuite: parentSuite
|
203
|
+
}),
|
204
|
+
beforeAllFn = jasmine.createSpy('beforeAll'),
|
205
|
+
afterAllFn = jasmine.createSpy('afterAll');
|
206
|
+
|
207
|
+
parentSuite.addChild(childSuite);
|
208
|
+
parentSuite.beforeAll(beforeAllFn);
|
209
|
+
parentSuite.afterAll(afterAllFn);
|
210
|
+
|
211
|
+
parentSuite.execute();
|
212
|
+
expect(fakeQueueRunnerForParent).toHaveBeenCalledWith(jasmine.objectContaining({queueableFns: []}));
|
120
213
|
});
|
121
214
|
|
122
215
|
it("calls a provided onStart callback when starting", function() {
|
@@ -130,7 +223,8 @@ describe("Suite", function() {
|
|
130
223
|
queueRunner: fakeQueueRunner
|
131
224
|
}),
|
132
225
|
fakeSpec1 = {
|
133
|
-
execute: jasmine.createSpy('fakeSpec1')
|
226
|
+
execute: jasmine.createSpy('fakeSpec1'),
|
227
|
+
isExecutable: function() { return true; }
|
134
228
|
};
|
135
229
|
|
136
230
|
suite.execute();
|
@@ -174,9 +268,47 @@ describe("Suite", function() {
|
|
174
268
|
|
175
269
|
expect(suiteResultsCallback).toHaveBeenCalledWith({
|
176
270
|
id: suite.id,
|
177
|
-
status: '',
|
271
|
+
status: 'finished',
|
272
|
+
description: "with a child suite",
|
273
|
+
fullName: "with a child suite",
|
274
|
+
failedExpectations: []
|
275
|
+
});
|
276
|
+
});
|
277
|
+
|
278
|
+
it("calls a provided result callback with status being disabled when disabled and done", function() {
|
279
|
+
var env = new j$.Env(),
|
280
|
+
suiteResultsCallback = jasmine.createSpy('suite result callback'),
|
281
|
+
fakeQueueRunner = function(attrs) { attrs.onComplete(); },
|
282
|
+
suite = new j$.Suite({
|
283
|
+
env: env,
|
284
|
+
description: "with a child suite",
|
285
|
+
queueRunner: fakeQueueRunner,
|
286
|
+
resultCallback: suiteResultsCallback
|
287
|
+
}),
|
288
|
+
fakeSpec1 = {
|
289
|
+
execute: jasmine.createSpy('fakeSpec1')
|
290
|
+
};
|
291
|
+
|
292
|
+
suite.disable();
|
293
|
+
|
294
|
+
suite.execute();
|
295
|
+
|
296
|
+
expect(suiteResultsCallback).toHaveBeenCalledWith({
|
297
|
+
id: suite.id,
|
298
|
+
status: 'disabled',
|
178
299
|
description: "with a child suite",
|
179
|
-
fullName: "with a child suite"
|
300
|
+
fullName: "with a child suite",
|
301
|
+
failedExpectations: []
|
180
302
|
});
|
181
303
|
});
|
304
|
+
|
305
|
+
it('has a status of failed if any afterAll expectations have failed', function() {
|
306
|
+
var suite = new j$.Suite({
|
307
|
+
expectationResultFactory: function() { return 'hi'; }
|
308
|
+
});
|
309
|
+
suite.addChild({ result: { status: 'done' } });
|
310
|
+
|
311
|
+
suite.addExpectationResult(false);
|
312
|
+
expect(suite.status()).toBe('failed');
|
313
|
+
});
|
182
314
|
});
|
@@ -10,4 +10,22 @@ describe("Timer", function() {
|
|
10
10
|
|
11
11
|
expect(timer.elapsed()).toEqual(100);
|
12
12
|
});
|
13
|
+
|
14
|
+
describe("when date is stubbed, perhaps by other testing helpers", function() {
|
15
|
+
var origDate = Date;
|
16
|
+
beforeEach(function() {
|
17
|
+
Date = jasmine.createSpy('date spy');
|
18
|
+
});
|
19
|
+
|
20
|
+
afterEach(function() {
|
21
|
+
Date = origDate;
|
22
|
+
});
|
23
|
+
|
24
|
+
it("does not throw even though Date was taken away", function() {
|
25
|
+
var timer = new j$.Timer();
|
26
|
+
|
27
|
+
expect(timer.start).not.toThrow();
|
28
|
+
expect(timer.elapsed()).toEqual(jasmine.any(Number));
|
29
|
+
});
|
30
|
+
});
|
13
31
|
});
|