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
@@ -1,4 +1,44 @@
|
|
1
1
|
describe("Env integration", function() {
|
2
|
+
beforeEach(function() {
|
3
|
+
jasmine.addMatchers({
|
4
|
+
toHaveFailedExpecationsForRunnable: function(util, customeEqualityTesters) {
|
5
|
+
return {
|
6
|
+
compare: function(actual, fullName, expectedFailures) {
|
7
|
+
var foundRunnable = false, expectations = true, foundFailures = [];
|
8
|
+
for (var i = 0; i < actual.calls.count(); i++) {
|
9
|
+
var args = actual.calls.argsFor(i)[0];
|
10
|
+
|
11
|
+
if (args.fullName === fullName) {
|
12
|
+
foundRunnable = true;
|
13
|
+
|
14
|
+
for (var j = 0; j < args.failedExpectations.length; j++) {
|
15
|
+
foundFailures.push(args.failedExpectations[j].message);
|
16
|
+
}
|
17
|
+
|
18
|
+
for (var j = 0; j < expectedFailures.length; j++) {
|
19
|
+
var failure = foundFailures[j];
|
20
|
+
var expectedFailure = expectedFailures[j];
|
21
|
+
|
22
|
+
if (Object.prototype.toString.call(expectedFailure) === '[object RegExp]') {
|
23
|
+
expectations = expectations && expectedFailure.test(failure);
|
24
|
+
} else {
|
25
|
+
expectations = expectations && failure === expectedFailure;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
break;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
return {
|
33
|
+
pass: foundRunnable && expectations,
|
34
|
+
message: !foundRunnable ? 'The runnable "' + fullName + '" never finished' :
|
35
|
+
'Expected runnable "' + fullName + '" to have failures ' + jasmine.pp(expectedFailures) + ' but it had ' + jasmine.pp(foundFailures)
|
36
|
+
};
|
37
|
+
}
|
38
|
+
};
|
39
|
+
}
|
40
|
+
});
|
41
|
+
});
|
2
42
|
|
3
43
|
it("Suites execute as expected (no nesting)", function(done) {
|
4
44
|
var env = new j$.Env(),
|
@@ -60,6 +100,21 @@ describe("Env integration", function() {
|
|
60
100
|
env.execute();
|
61
101
|
});
|
62
102
|
|
103
|
+
it('Tells the reporter when the top-level suite has started and finished', function(done) {
|
104
|
+
var env = new j$.Env(),
|
105
|
+
reporter = jasmine.createSpyObj('reporter', ['suiteStarted', 'suiteDone', 'jasmineDone']);
|
106
|
+
|
107
|
+
reporter.jasmineDone.and.callFake(function() {
|
108
|
+
expect(reporter.suiteStarted).toHaveBeenCalled();
|
109
|
+
expect(reporter.suiteDone).toHaveBeenCalled();
|
110
|
+
done();
|
111
|
+
});
|
112
|
+
|
113
|
+
env.addReporter(reporter);
|
114
|
+
|
115
|
+
env.execute();
|
116
|
+
});
|
117
|
+
|
63
118
|
it("Multiple top-level Suites execute as expected", function(done) {
|
64
119
|
var env = new j$.Env(),
|
65
120
|
calls = [];
|
@@ -80,7 +135,7 @@ describe("Env integration", function() {
|
|
80
135
|
|
81
136
|
env.describe("Outer suite", function() {
|
82
137
|
env.it("an outer spec", function() {
|
83
|
-
calls.push('an outer spec')
|
138
|
+
calls.push('an outer spec');
|
84
139
|
});
|
85
140
|
env.describe("Inner suite", function() {
|
86
141
|
env.it("an inner spec", function() {
|
@@ -101,6 +156,53 @@ describe("Env integration", function() {
|
|
101
156
|
env.execute();
|
102
157
|
});
|
103
158
|
|
159
|
+
it('explicitly fails a spec', function(done) {
|
160
|
+
var env = new j$.Env(),
|
161
|
+
specDone = jasmine.createSpy('specDone');
|
162
|
+
|
163
|
+
env.addReporter({
|
164
|
+
specDone: specDone,
|
165
|
+
jasmineDone: function() {
|
166
|
+
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
167
|
+
description: 'has a default message',
|
168
|
+
failedExpectations: [jasmine.objectContaining({
|
169
|
+
message: 'Failed'
|
170
|
+
})]
|
171
|
+
}));
|
172
|
+
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
173
|
+
description: 'specifies a message',
|
174
|
+
failedExpectations: [jasmine.objectContaining({
|
175
|
+
message: 'Failed: messy message'
|
176
|
+
})]
|
177
|
+
}));
|
178
|
+
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
179
|
+
description: 'has a message from an Error',
|
180
|
+
failedExpectations: [jasmine.objectContaining({
|
181
|
+
message: 'Failed: error message'
|
182
|
+
})]
|
183
|
+
}));
|
184
|
+
done();
|
185
|
+
}
|
186
|
+
});
|
187
|
+
|
188
|
+
env.describe('failing', function() {
|
189
|
+
env.it('has a default message', function() {
|
190
|
+
env.fail();
|
191
|
+
});
|
192
|
+
|
193
|
+
env.it('specifies a message', function() {
|
194
|
+
env.fail('messy message');
|
195
|
+
});
|
196
|
+
|
197
|
+
env.it('has a message from an Error', function() {
|
198
|
+
env.fail(new Error('error message'));
|
199
|
+
});
|
200
|
+
});
|
201
|
+
|
202
|
+
env.execute();
|
203
|
+
});
|
204
|
+
|
205
|
+
|
104
206
|
it("calls associated befores/specs/afters with the same 'this'", function(done) {
|
105
207
|
var env = new j$.Env();
|
106
208
|
|
@@ -165,6 +267,305 @@ describe("Env integration", function() {
|
|
165
267
|
env.execute();
|
166
268
|
});
|
167
269
|
|
270
|
+
it("calls associated beforeAlls/afterAlls only once per suite", function(done) {
|
271
|
+
var env = new j$.Env(),
|
272
|
+
before = jasmine.createSpy('beforeAll'),
|
273
|
+
after = jasmine.createSpy('afterAll');
|
274
|
+
|
275
|
+
env.addReporter({
|
276
|
+
jasmineDone: function() {
|
277
|
+
expect(after).toHaveBeenCalled();
|
278
|
+
expect(after.calls.count()).toBe(1);
|
279
|
+
expect(before.calls.count()).toBe(1);
|
280
|
+
done();
|
281
|
+
}
|
282
|
+
});
|
283
|
+
|
284
|
+
env.describe("with beforeAll and afterAll", function() {
|
285
|
+
env.it("spec", function() {
|
286
|
+
expect(before).toHaveBeenCalled();
|
287
|
+
expect(after).not.toHaveBeenCalled();
|
288
|
+
});
|
289
|
+
|
290
|
+
env.it("another spec", function() {
|
291
|
+
expect(before).toHaveBeenCalled();
|
292
|
+
expect(after).not.toHaveBeenCalled();
|
293
|
+
});
|
294
|
+
|
295
|
+
env.beforeAll(before);
|
296
|
+
env.afterAll(after);
|
297
|
+
});
|
298
|
+
|
299
|
+
env.execute();
|
300
|
+
});
|
301
|
+
|
302
|
+
it("calls associated beforeAlls/afterAlls only once per suite for async", function(done) {
|
303
|
+
var env = new j$.Env(),
|
304
|
+
before = jasmine.createSpy('beforeAll'),
|
305
|
+
after = jasmine.createSpy('afterAll');
|
306
|
+
|
307
|
+
env.addReporter({
|
308
|
+
jasmineDone: function() {
|
309
|
+
expect(after).toHaveBeenCalled();
|
310
|
+
expect(after.calls.count()).toBe(1);
|
311
|
+
expect(before.calls.count()).toBe(1);
|
312
|
+
done();
|
313
|
+
}
|
314
|
+
});
|
315
|
+
|
316
|
+
env.describe("with beforeAll and afterAll", function() {
|
317
|
+
env.it("spec", function() {
|
318
|
+
expect(before).toHaveBeenCalled();
|
319
|
+
expect(after).not.toHaveBeenCalled();
|
320
|
+
});
|
321
|
+
|
322
|
+
env.it("another spec", function() {
|
323
|
+
expect(before).toHaveBeenCalled();
|
324
|
+
expect(after).not.toHaveBeenCalled();
|
325
|
+
});
|
326
|
+
|
327
|
+
env.beforeAll(function(beforeCallbackUnderTest) {
|
328
|
+
before();
|
329
|
+
beforeCallbackUnderTest();
|
330
|
+
});
|
331
|
+
|
332
|
+
env.afterAll(function(afterCallbackUnderTest) {
|
333
|
+
after();
|
334
|
+
afterCallbackUnderTest();
|
335
|
+
});
|
336
|
+
});
|
337
|
+
|
338
|
+
env.execute();
|
339
|
+
});
|
340
|
+
|
341
|
+
it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) {
|
342
|
+
var env = new j$.Env();
|
343
|
+
|
344
|
+
env.addReporter({jasmineDone: done});
|
345
|
+
|
346
|
+
env.describe("with beforeAll and afterAll", function() {
|
347
|
+
env.beforeAll(function() {
|
348
|
+
this.x = 1;
|
349
|
+
});
|
350
|
+
|
351
|
+
env.it("has an x at the root", function() {
|
352
|
+
expect(this.x).toBe(1);
|
353
|
+
});
|
354
|
+
|
355
|
+
env.describe("child that deletes", function() {
|
356
|
+
env.beforeAll(function() {
|
357
|
+
expect(this.x).toBe(1);
|
358
|
+
delete this.x;
|
359
|
+
});
|
360
|
+
|
361
|
+
env.it("has no x", function() {
|
362
|
+
expect(this.x).not.toBeDefined();
|
363
|
+
});
|
364
|
+
});
|
365
|
+
|
366
|
+
env.describe("child should still have x", function() {
|
367
|
+
env.beforeAll(function(innerDone) {
|
368
|
+
expect(this.x).toBe(1);
|
369
|
+
innerDone();
|
370
|
+
});
|
371
|
+
|
372
|
+
env.it("has an x", function() {
|
373
|
+
expect(this.x).toBe(1);
|
374
|
+
delete this.x;
|
375
|
+
});
|
376
|
+
|
377
|
+
env.it("still has an x", function() {
|
378
|
+
expect(this.x).toBe(1);
|
379
|
+
});
|
380
|
+
|
381
|
+
env.it("adds a y", function() {
|
382
|
+
this.y = 2;
|
383
|
+
expect(this.y).toBe(2);
|
384
|
+
});
|
385
|
+
|
386
|
+
env.it("doesn't have y that was added in sibling", function() {
|
387
|
+
expect(this.y).not.toBeDefined();
|
388
|
+
});
|
389
|
+
});
|
390
|
+
});
|
391
|
+
|
392
|
+
env.execute();
|
393
|
+
});
|
394
|
+
|
395
|
+
it("fails all underlying specs when the beforeAll fails", function (done) {
|
396
|
+
var env = new j$.Env(),
|
397
|
+
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
|
398
|
+
|
399
|
+
reporter.jasmineDone.and.callFake(function() {
|
400
|
+
expect(reporter.specDone.calls.count()).toEqual(2);
|
401
|
+
|
402
|
+
expect(reporter.specDone.calls.argsFor(0)[0])
|
403
|
+
.toEqual(jasmine.objectContaining({status: 'failed'}));
|
404
|
+
expect(reporter.specDone.calls.argsFor(0)[0].failedExpectations[0].message)
|
405
|
+
.toEqual("Expected 1 to be 2.");
|
406
|
+
|
407
|
+
expect(reporter.specDone.calls.argsFor(1)[0])
|
408
|
+
.toEqual(jasmine.objectContaining({status: 'failed'}));
|
409
|
+
expect(reporter.specDone.calls.argsFor(1)[0].failedExpectations[0].message)
|
410
|
+
.toEqual("Expected 1 to be 2.");
|
411
|
+
done();
|
412
|
+
});
|
413
|
+
|
414
|
+
env.addReporter(reporter);
|
415
|
+
|
416
|
+
env.describe('A suite', function(){
|
417
|
+
env.beforeAll(function() {
|
418
|
+
env.expect(1).toBe(2);
|
419
|
+
});
|
420
|
+
|
421
|
+
env.it("spec that will be failed", function() {
|
422
|
+
});
|
423
|
+
|
424
|
+
env.describe("nesting", function() {
|
425
|
+
env.it("another spec to fail", function() {
|
426
|
+
});
|
427
|
+
});
|
428
|
+
});
|
429
|
+
|
430
|
+
env.execute();
|
431
|
+
});
|
432
|
+
|
433
|
+
describe('suiteDone reporting', function(){
|
434
|
+
it("reports when an afterAll fails an expectation", function(done) {
|
435
|
+
var env = new j$.Env(),
|
436
|
+
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
437
|
+
|
438
|
+
reporter.jasmineDone.and.callFake(function() {
|
439
|
+
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('my suite', [
|
440
|
+
'Expected 1 to equal 2.',
|
441
|
+
'Expected 2 to equal 3.'
|
442
|
+
]);
|
443
|
+
done();
|
444
|
+
});
|
445
|
+
|
446
|
+
env.addReporter(reporter);
|
447
|
+
|
448
|
+
env.describe('my suite', function() {
|
449
|
+
env.it('my spec', function() {
|
450
|
+
});
|
451
|
+
|
452
|
+
env.afterAll(function() {
|
453
|
+
env.expect(1).toEqual(2);
|
454
|
+
env.expect(2).toEqual(3);
|
455
|
+
});
|
456
|
+
});
|
457
|
+
|
458
|
+
env.execute();
|
459
|
+
});
|
460
|
+
|
461
|
+
it("if there are no specs, it still reports correctly", function(done) {
|
462
|
+
var env = new j$.Env(),
|
463
|
+
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
464
|
+
|
465
|
+
reporter.jasmineDone.and.callFake(function() {
|
466
|
+
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('outer suite', [
|
467
|
+
'Expected 1 to equal 2.',
|
468
|
+
'Expected 2 to equal 3.'
|
469
|
+
]);
|
470
|
+
done();
|
471
|
+
});
|
472
|
+
|
473
|
+
env.addReporter(reporter);
|
474
|
+
|
475
|
+
env.describe('outer suite', function() {
|
476
|
+
env.describe('inner suite', function() {
|
477
|
+
env.it('spec', function(){ });
|
478
|
+
});
|
479
|
+
|
480
|
+
env.afterAll(function() {
|
481
|
+
env.expect(1).toEqual(2);
|
482
|
+
env.expect(2).toEqual(3);
|
483
|
+
});
|
484
|
+
});
|
485
|
+
|
486
|
+
env.execute();
|
487
|
+
});
|
488
|
+
|
489
|
+
it("reports when afterAll throws an exception", function(done) {
|
490
|
+
var env = new j$.Env(),
|
491
|
+
error = new Error('After All Exception'),
|
492
|
+
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
493
|
+
|
494
|
+
reporter.jasmineDone.and.callFake(function() {
|
495
|
+
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('my suite', [
|
496
|
+
(/^Error: After All Exception/)
|
497
|
+
]);
|
498
|
+
done();
|
499
|
+
});
|
500
|
+
|
501
|
+
env.addReporter(reporter);
|
502
|
+
|
503
|
+
env.describe('my suite', function() {
|
504
|
+
env.it('my spec', function() {
|
505
|
+
});
|
506
|
+
|
507
|
+
env.afterAll(function() {
|
508
|
+
throw error;
|
509
|
+
});
|
510
|
+
});
|
511
|
+
|
512
|
+
env.execute();
|
513
|
+
});
|
514
|
+
|
515
|
+
it("reports when an async afterAll fails an expectation", function(done) {
|
516
|
+
var env = new j$.Env(),
|
517
|
+
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
518
|
+
|
519
|
+
reporter.jasmineDone.and.callFake(function() {
|
520
|
+
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('my suite', [
|
521
|
+
'Expected 1 to equal 2.'
|
522
|
+
]);
|
523
|
+
done();
|
524
|
+
});
|
525
|
+
|
526
|
+
env.addReporter(reporter);
|
527
|
+
|
528
|
+
env.describe('my suite', function() {
|
529
|
+
env.it('my spec', function() {
|
530
|
+
});
|
531
|
+
|
532
|
+
env.afterAll(function(afterAllDone) {
|
533
|
+
env.expect(1).toEqual(2);
|
534
|
+
afterAllDone();
|
535
|
+
});
|
536
|
+
});
|
537
|
+
|
538
|
+
env.execute();
|
539
|
+
});
|
540
|
+
|
541
|
+
it("reports when an async afterAll throws an exception", function(done) {
|
542
|
+
var env = new j$.Env(),
|
543
|
+
error = new Error('After All Exception'),
|
544
|
+
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
545
|
+
|
546
|
+
|
547
|
+
reporter.jasmineDone.and.callFake(function() {
|
548
|
+
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('my suite', [
|
549
|
+
(/^Error: After All Exception/)
|
550
|
+
]);
|
551
|
+
done();
|
552
|
+
});
|
553
|
+
|
554
|
+
env.addReporter(reporter);
|
555
|
+
|
556
|
+
env.describe('my suite', function() {
|
557
|
+
env.it('my spec', function() {
|
558
|
+
});
|
559
|
+
|
560
|
+
env.afterAll(function(afterAllDone) {
|
561
|
+
throw error;
|
562
|
+
});
|
563
|
+
});
|
564
|
+
|
565
|
+
env.execute();
|
566
|
+
});
|
567
|
+
});
|
568
|
+
|
168
569
|
it("Allows specifying which specs and suites to run", function(done) {
|
169
570
|
var env = new j$.Env(),
|
170
571
|
calls = [],
|
@@ -201,16 +602,61 @@ describe("Env integration", function() {
|
|
201
602
|
env.execute([secondSuite.id, firstSpec.id]);
|
202
603
|
});
|
203
604
|
|
204
|
-
it(
|
205
|
-
|
605
|
+
it('runs before and after all functions for runnables provided to .execute()', function(done) {
|
606
|
+
var env = new j$.Env(),
|
607
|
+
calls = [],
|
608
|
+
first_spec,
|
609
|
+
second_spec;
|
206
610
|
|
207
|
-
|
208
|
-
|
611
|
+
var assertions = function() {
|
612
|
+
expect(calls).toEqual([
|
613
|
+
"before",
|
614
|
+
"first spec",
|
615
|
+
"after",
|
616
|
+
"before",
|
617
|
+
"second spec",
|
618
|
+
"after"
|
619
|
+
]);
|
620
|
+
done();
|
621
|
+
};
|
209
622
|
|
210
|
-
|
623
|
+
env.addReporter({jasmineDone: assertions});
|
211
624
|
|
212
|
-
|
625
|
+
env.describe("first suite", function() {
|
626
|
+
env.beforeAll(function() {
|
627
|
+
calls.push("before");
|
628
|
+
});
|
629
|
+
env.afterAll(function() {
|
630
|
+
calls.push("after")
|
631
|
+
});
|
632
|
+
first_spec = env.it("spec", function() {
|
633
|
+
calls.push('first spec');
|
634
|
+
});
|
635
|
+
second_spec = env.it("spec 2", function() {
|
636
|
+
calls.push("second spec");
|
637
|
+
});
|
638
|
+
});
|
639
|
+
|
640
|
+
env.execute([first_spec.id, second_spec.id]);
|
641
|
+
});
|
642
|
+
|
643
|
+
it("Functions can be spied on and have their calls tracked", function (done) {
|
644
|
+
var env = new j$.Env();
|
645
|
+
|
646
|
+
var originalFunctionWasCalled = false;
|
647
|
+
var subject = {
|
648
|
+
spiedFunc: function() {
|
649
|
+
originalFunctionWasCalled = true;
|
650
|
+
return "original result";
|
651
|
+
}
|
652
|
+
};
|
653
|
+
|
654
|
+
env.addReporter({jasmineDone: done});
|
655
|
+
|
656
|
+
env.it("works with spies", function() {
|
657
|
+
var spy = env.spyOn(subject, 'spiedFunc').and.returnValue("stubbed result");
|
213
658
|
|
659
|
+
expect(subject.spiedFunc).toEqual(spy);
|
214
660
|
expect(subject.spiedFunc.calls.any()).toEqual(false);
|
215
661
|
expect(subject.spiedFunc.calls.count()).toEqual(0);
|
216
662
|
|
@@ -220,11 +666,76 @@ describe("Env integration", function() {
|
|
220
666
|
expect(subject.spiedFunc.calls.count()).toEqual(1);
|
221
667
|
expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['foo']);
|
222
668
|
expect(subject.spiedFunc.calls.mostRecent().object).toEqual(subject);
|
669
|
+
expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual("stubbed result");
|
223
670
|
expect(originalFunctionWasCalled).toEqual(false);
|
224
671
|
|
672
|
+
subject.spiedFunc.and.callThrough();
|
225
673
|
subject.spiedFunc('bar');
|
226
674
|
expect(subject.spiedFunc.calls.count()).toEqual(2);
|
227
675
|
expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['bar']);
|
676
|
+
expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual("original result");
|
677
|
+
expect(originalFunctionWasCalled).toEqual(true);
|
678
|
+
});
|
679
|
+
|
680
|
+
env.execute();
|
681
|
+
});
|
682
|
+
|
683
|
+
it('removes all spies added in a spec after the spec is complete', function(done) {
|
684
|
+
var env = new j$.Env(),
|
685
|
+
originalFoo = function() {},
|
686
|
+
testObj = {
|
687
|
+
foo: originalFoo
|
688
|
+
},
|
689
|
+
firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
|
690
|
+
env.spyOn(testObj, 'foo');
|
691
|
+
}),
|
692
|
+
secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
|
693
|
+
expect(testObj.foo).toBe(originalFoo);
|
694
|
+
});
|
695
|
+
env.describe('test suite', function() {
|
696
|
+
env.it('spec 0', firstSpec);
|
697
|
+
env.it('spec 1', secondSpec);
|
698
|
+
});
|
699
|
+
|
700
|
+
var assertions = function() {
|
701
|
+
expect(firstSpec).toHaveBeenCalled();
|
702
|
+
expect(secondSpec).toHaveBeenCalled();
|
703
|
+
done();
|
704
|
+
};
|
705
|
+
|
706
|
+
env.addReporter({ jasmineDone: assertions });
|
707
|
+
|
708
|
+
env.execute();
|
709
|
+
});
|
710
|
+
|
711
|
+
it('removes all spies added in a suite after the suite is complete', function(done) {
|
712
|
+
var env = new j$.Env(),
|
713
|
+
originalFoo = function() {},
|
714
|
+
testObj = {
|
715
|
+
foo: originalFoo
|
716
|
+
};
|
717
|
+
|
718
|
+
env.describe('test suite', function() {
|
719
|
+
env.beforeAll(function() { env.spyOn(testObj, 'foo');})
|
720
|
+
|
721
|
+
env.it('spec 0', function() {
|
722
|
+
expect(j$.isSpy(testObj.foo)).toBe(true);
|
723
|
+
});
|
724
|
+
|
725
|
+
env.it('spec 1', function() {
|
726
|
+
expect(j$.isSpy(testObj.foo)).toBe(true);
|
727
|
+
});
|
728
|
+
});
|
729
|
+
|
730
|
+
env.describe('another suite', function() {
|
731
|
+
env.it('spec 2', function() {
|
732
|
+
expect(j$.isSpy(testObj.foo)).toBe(false);
|
733
|
+
});
|
734
|
+
});
|
735
|
+
|
736
|
+
env.addReporter({ jasmineDone: done });
|
737
|
+
|
738
|
+
env.execute();
|
228
739
|
});
|
229
740
|
|
230
741
|
it("Mock clock can be installed and used in tests", function(done) {
|
@@ -289,20 +800,24 @@ describe("Env integration", function() {
|
|
289
800
|
|
290
801
|
beforeEach(function() {
|
291
802
|
originalTimeout = j$.DEFAULT_TIMEOUT_INTERVAL;
|
292
|
-
jasmine.
|
803
|
+
jasmine.clock().install();
|
293
804
|
});
|
294
805
|
|
295
806
|
afterEach(function() {
|
296
|
-
jasmine.
|
807
|
+
jasmine.clock().uninstall();
|
297
808
|
j$.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
298
809
|
});
|
299
810
|
|
300
811
|
it("should wait a specified interval before failing specs haven't called done yet", function(done) {
|
301
812
|
var env = new j$.Env(),
|
302
|
-
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone" ]);
|
813
|
+
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
|
303
814
|
|
304
815
|
reporter.specDone.and.callFake(function() {
|
305
816
|
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({status: 'failed'}));
|
817
|
+
});
|
818
|
+
|
819
|
+
reporter.jasmineDone.and.callFake(function() {
|
820
|
+
expect(reporter.jasmineDone.calls.count()).toEqual(1);
|
306
821
|
done();
|
307
822
|
});
|
308
823
|
|
@@ -311,30 +826,284 @@ describe("Env integration", function() {
|
|
311
826
|
|
312
827
|
env.it("async spec that doesn't call done", function(underTestCallback) {
|
313
828
|
env.expect(true).toBeTruthy();
|
314
|
-
jasmine.
|
829
|
+
jasmine.clock().tick(8416);
|
315
830
|
});
|
316
831
|
|
317
832
|
env.execute();
|
318
833
|
});
|
319
|
-
});
|
320
834
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
reporter = jasmine.createSpyObj('fakeReporter', [
|
325
|
-
"jasmineStarted",
|
326
|
-
"jasmineDone",
|
327
|
-
"suiteStarted",
|
328
|
-
"suiteDone",
|
329
|
-
"specStarted",
|
330
|
-
"specDone"
|
331
|
-
]);
|
835
|
+
it("should wait a specified interval before failing beforeAll's and their associated specs that haven't called done", function(done) {
|
836
|
+
var env = new j$.Env(),
|
837
|
+
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
|
332
838
|
|
333
|
-
|
334
|
-
|
839
|
+
reporter.jasmineDone.and.callFake(function() {
|
840
|
+
expect(reporter.specDone.calls.count()).toEqual(2);
|
841
|
+
expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(jasmine.objectContaining({status: 'failed'}));
|
842
|
+
expect(reporter.specDone.calls.argsFor(1)[0]).toEqual(jasmine.objectContaining({status: 'failed'}));
|
843
|
+
done();
|
844
|
+
});
|
845
|
+
|
846
|
+
env.addReporter(reporter);
|
847
|
+
j$.DEFAULT_TIMEOUT_INTERVAL = 1290;
|
848
|
+
|
849
|
+
env.beforeAll(function(done) {
|
850
|
+
jasmine.clock().tick(1290);
|
851
|
+
});
|
852
|
+
|
853
|
+
env.it("spec that will be failed", function() {
|
854
|
+
});
|
855
|
+
|
856
|
+
env.describe("nesting", function() {
|
857
|
+
env.it("another spec to fail", function() {
|
858
|
+
});
|
859
|
+
});
|
860
|
+
|
861
|
+
env.execute();
|
862
|
+
});
|
863
|
+
|
864
|
+
it("should wait the specified interval before reporting an afterAll that fails to call done", function(done) {
|
865
|
+
var env = new j$.Env(),
|
866
|
+
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
867
|
+
|
868
|
+
reporter.jasmineDone.and.callFake(function() {
|
869
|
+
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('my suite', [
|
870
|
+
(/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
|
871
|
+
]);
|
872
|
+
done();
|
873
|
+
});
|
874
|
+
|
875
|
+
env.addReporter(reporter);
|
876
|
+
j$.DEFAULT_TIMEOUT_INTERVAL = 3000;
|
877
|
+
|
878
|
+
env.describe('my suite', function() {
|
879
|
+
env.it('my spec', function() {
|
880
|
+
});
|
881
|
+
|
882
|
+
env.afterAll(function(innerDone) {
|
883
|
+
jasmine.clock().tick(3001);
|
884
|
+
innerDone();
|
885
|
+
});
|
886
|
+
});
|
887
|
+
|
888
|
+
env.execute();
|
889
|
+
});
|
890
|
+
|
891
|
+
it('should wait a custom interval before reporting async functions that fail to call done', function(done) {
|
892
|
+
var env = new j$.Env(),
|
893
|
+
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']);
|
894
|
+
|
895
|
+
reporter.jasmineDone.and.callFake(function() {
|
896
|
+
expect(reporter.specDone).toHaveFailedExpecationsForRunnable('suite beforeAll times out', [
|
897
|
+
(/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
|
898
|
+
]);
|
899
|
+
|
900
|
+
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('suite afterAll', [
|
901
|
+
(/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
|
902
|
+
]);
|
903
|
+
|
904
|
+
expect(reporter.specDone).toHaveFailedExpecationsForRunnable('suite beforeEach times out', [
|
905
|
+
(/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
|
906
|
+
]);
|
907
|
+
|
908
|
+
expect(reporter.specDone).toHaveFailedExpecationsForRunnable('suite afterEach times out', [
|
909
|
+
(/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
|
910
|
+
]);
|
911
|
+
|
912
|
+
expect(reporter.specDone).toHaveFailedExpecationsForRunnable('suite it times out', [
|
913
|
+
(/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
|
914
|
+
]);
|
915
|
+
|
916
|
+
done();
|
917
|
+
});
|
918
|
+
|
919
|
+
env.addReporter(reporter);
|
920
|
+
j$.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
921
|
+
|
922
|
+
env.describe('suite', function() {
|
923
|
+
env.describe('beforeAll', function() {
|
924
|
+
env.beforeAll(function(innerDone) {
|
925
|
+
jasmine.clock().tick(5001);
|
926
|
+
innerDone();
|
927
|
+
}, 5000);
|
928
|
+
|
929
|
+
env.it('times out', function() {});
|
930
|
+
});
|
931
|
+
|
932
|
+
env.describe('afterAll', function() {
|
933
|
+
env.afterAll(function(innerDone) {
|
934
|
+
jasmine.clock().tick(2001);
|
935
|
+
innerDone();
|
936
|
+
}, 2000);
|
937
|
+
|
938
|
+
env.it('times out', function() {});
|
939
|
+
});
|
940
|
+
|
941
|
+
env.describe('beforeEach', function() {
|
942
|
+
env.beforeEach(function(innerDone) {
|
943
|
+
jasmine.clock().tick(1001);
|
944
|
+
innerDone();
|
945
|
+
}, 1000);
|
946
|
+
|
947
|
+
env.it('times out', function() {});
|
948
|
+
});
|
949
|
+
|
950
|
+
env.describe('afterEach', function() {
|
951
|
+
env.afterEach(function(innerDone) {
|
952
|
+
jasmine.clock().tick(4001);
|
953
|
+
innerDone();
|
954
|
+
}, 4000);
|
955
|
+
|
956
|
+
env.it('times out', function() {});
|
957
|
+
});
|
958
|
+
|
959
|
+
env.it('it times out', function(innerDone) {
|
960
|
+
jasmine.clock().tick(6001);
|
961
|
+
innerDone();
|
962
|
+
}, 6000);
|
963
|
+
});
|
964
|
+
|
965
|
+
env.execute();
|
966
|
+
});
|
967
|
+
|
968
|
+
it('explicitly fails an async spec', function(done) {
|
969
|
+
var env = new j$.Env(),
|
970
|
+
specDone = jasmine.createSpy('specDone');
|
971
|
+
|
972
|
+
env.addReporter({
|
973
|
+
specDone: specDone,
|
974
|
+
specStarted: function() {
|
975
|
+
jasmine.clock().tick(1);
|
976
|
+
},
|
977
|
+
jasmineDone: function() {
|
978
|
+
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
979
|
+
description: 'has a default message',
|
980
|
+
failedExpectations: [jasmine.objectContaining({
|
981
|
+
message: 'Failed'
|
982
|
+
})]
|
983
|
+
}));
|
984
|
+
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
985
|
+
description: 'specifies a message',
|
986
|
+
failedExpectations: [jasmine.objectContaining({
|
987
|
+
message: 'Failed: messy message'
|
988
|
+
})]
|
989
|
+
}));
|
990
|
+
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
991
|
+
description: 'fails via the done callback',
|
992
|
+
failedExpectations: [jasmine.objectContaining({
|
993
|
+
message: 'Failed: done failed'
|
994
|
+
})]
|
995
|
+
}));
|
996
|
+
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
997
|
+
description: 'has a message from an Error',
|
998
|
+
failedExpectations: [jasmine.objectContaining({
|
999
|
+
message: 'Failed: error message'
|
1000
|
+
})]
|
1001
|
+
}));
|
1002
|
+
done();
|
1003
|
+
}
|
1004
|
+
});
|
1005
|
+
|
1006
|
+
env.describe('failing', function() {
|
1007
|
+
env.it('has a default message', function(innerDone) {
|
1008
|
+
setTimeout(function() {
|
1009
|
+
env.fail();
|
1010
|
+
innerDone();
|
1011
|
+
}, 1);
|
1012
|
+
});
|
1013
|
+
|
1014
|
+
env.it('specifies a message', function(innerDone) {
|
1015
|
+
setTimeout(function() {
|
1016
|
+
env.fail('messy message');
|
1017
|
+
innerDone();
|
1018
|
+
}, 1);
|
1019
|
+
});
|
1020
|
+
|
1021
|
+
env.it('fails via the done callback', function(innerDone) {
|
1022
|
+
setTimeout(function() {
|
1023
|
+
innerDone.fail('done failed');
|
1024
|
+
}, 1);
|
1025
|
+
});
|
1026
|
+
|
1027
|
+
env.it('has a message from an Error', function(innerDone) {
|
1028
|
+
setTimeout(function() {
|
1029
|
+
env.fail(new Error('error message'));
|
1030
|
+
innerDone();
|
1031
|
+
}, 1);
|
1032
|
+
});
|
1033
|
+
});
|
1034
|
+
|
1035
|
+
env.execute();
|
1036
|
+
});
|
1037
|
+
});
|
1038
|
+
|
1039
|
+
describe('focused tests', function() {
|
1040
|
+
it('should only run the focused tests', function(done) {
|
1041
|
+
var env = new j$.Env(),
|
1042
|
+
calls = [];
|
1043
|
+
|
1044
|
+
var assertions = function() {
|
1045
|
+
expect(calls).toEqual(['focused']);
|
1046
|
+
done();
|
1047
|
+
};
|
1048
|
+
|
1049
|
+
env.addReporter({jasmineDone: assertions});
|
1050
|
+
|
1051
|
+
env.describe('a suite', function() {
|
1052
|
+
env.fit('is focused', function() {
|
1053
|
+
calls.push('focused');
|
1054
|
+
});
|
1055
|
+
|
1056
|
+
env.it('is not focused', function() {
|
1057
|
+
calls.push('freakout');
|
1058
|
+
})
|
1059
|
+
});
|
1060
|
+
|
1061
|
+
env.execute();
|
1062
|
+
});
|
1063
|
+
|
1064
|
+
it('should only run focused suites', function(){
|
1065
|
+
var env = new j$.Env(),
|
1066
|
+
calls = [];
|
1067
|
+
|
1068
|
+
var assertions = function() {
|
1069
|
+
expect(calls).toEqual(['focused']);
|
1070
|
+
done();
|
1071
|
+
};
|
1072
|
+
|
1073
|
+
env.addReporter({jasmineDone: assertions});
|
1074
|
+
|
1075
|
+
env.fdescribe('a focused suite', function() {
|
1076
|
+
env.it('is focused', function() {
|
1077
|
+
calls.push('focused');
|
1078
|
+
});
|
1079
|
+
});
|
1080
|
+
|
1081
|
+
env.describe('a regular suite', function() {
|
1082
|
+
env.it('is not focused', function() {
|
1083
|
+
calls.push('freakout');
|
1084
|
+
})
|
1085
|
+
});
|
1086
|
+
|
1087
|
+
env.execute();
|
1088
|
+
});
|
1089
|
+
});
|
1090
|
+
|
1091
|
+
it("should report as expected", function(done) {
|
1092
|
+
var env = new j$.Env(),
|
1093
|
+
reporter = jasmine.createSpyObj('fakeReporter', [
|
1094
|
+
"jasmineStarted",
|
1095
|
+
"jasmineDone",
|
1096
|
+
"suiteStarted",
|
1097
|
+
"suiteDone",
|
1098
|
+
"specStarted",
|
1099
|
+
"specDone"
|
1100
|
+
]);
|
1101
|
+
|
1102
|
+
reporter.jasmineDone.and.callFake(function() {
|
1103
|
+
expect(reporter.jasmineStarted).toHaveBeenCalledWith({
|
335
1104
|
totalSpecsDefined: 3
|
336
1105
|
});
|
337
|
-
var suiteResult = reporter.suiteStarted.calls.
|
1106
|
+
var suiteResult = reporter.suiteStarted.calls.argsFor(1)[0];
|
338
1107
|
expect(suiteResult.description).toEqual("A Suite");
|
339
1108
|
|
340
1109
|
done();
|
@@ -384,11 +1153,7 @@ describe("Env integration", function() {
|
|
384
1153
|
it("Custom equality testers should be per spec", function(done) {
|
385
1154
|
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
386
1155
|
reporter = jasmine.createSpyObj('fakeReporter', [
|
387
|
-
"jasmineStarted",
|
388
1156
|
"jasmineDone",
|
389
|
-
"suiteStarted",
|
390
|
-
"suiteDone",
|
391
|
-
"specStarted",
|
392
1157
|
"specDone"
|
393
1158
|
]);
|
394
1159
|
|
@@ -418,30 +1183,42 @@ describe("Env integration", function() {
|
|
418
1183
|
env.execute();
|
419
1184
|
});
|
420
1185
|
|
421
|
-
it("Custom
|
1186
|
+
it("Custom equality testers should be per suite", function(done) {
|
422
1187
|
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
423
|
-
matchers = {
|
424
|
-
toFoo: function() {}
|
425
|
-
},
|
426
1188
|
reporter = jasmine.createSpyObj('fakeReporter', [
|
427
|
-
"jasmineStarted",
|
428
1189
|
"jasmineDone",
|
429
|
-
"suiteStarted",
|
430
|
-
"suiteDone",
|
431
|
-
"specStarted",
|
432
1190
|
"specDone"
|
433
1191
|
]);
|
434
1192
|
|
1193
|
+
reporter.jasmineDone.and.callFake(function() {
|
1194
|
+
var firstSpecResult = reporter.specDone.calls.first().args[0],
|
1195
|
+
secondSpecResult = reporter.specDone.calls.argsFor(0)[0],
|
1196
|
+
thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];
|
1197
|
+
|
1198
|
+
expect(firstSpecResult.status).toEqual("passed");
|
1199
|
+
expect(secondSpecResult.status).toEqual("passed");
|
1200
|
+
expect(thirdSpecResult.status).toEqual("failed");
|
1201
|
+
|
1202
|
+
done();
|
1203
|
+
});
|
1204
|
+
|
435
1205
|
env.addReporter(reporter);
|
436
1206
|
|
437
|
-
env.describe("testing custom
|
438
|
-
env.
|
439
|
-
|
440
|
-
|
1207
|
+
env.describe("testing custom equality testers", function() {
|
1208
|
+
env.beforeAll(function() { env.addCustomEqualityTester(function(a, b) { return true; }); });
|
1209
|
+
|
1210
|
+
env.it("with a custom tester", function() {
|
1211
|
+
env.expect("a").toEqual("b");
|
441
1212
|
});
|
442
1213
|
|
443
|
-
env.it("
|
444
|
-
|
1214
|
+
env.it("with the same custom tester", function() {
|
1215
|
+
env.expect("a").toEqual("b");
|
1216
|
+
});
|
1217
|
+
});
|
1218
|
+
|
1219
|
+
env.describe("another suite", function() {
|
1220
|
+
env.it("without the custom tester", function(){
|
1221
|
+
env.expect("a").toEqual("b");
|
445
1222
|
});
|
446
1223
|
});
|
447
1224
|
|
@@ -451,11 +1228,7 @@ describe("Env integration", function() {
|
|
451
1228
|
it("Custom equality testers for toContain should be per spec", function(done) {
|
452
1229
|
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
453
1230
|
reporter = jasmine.createSpyObj('fakeReporter', [
|
454
|
-
"jasmineStarted",
|
455
1231
|
"jasmineDone",
|
456
|
-
"suiteStarted",
|
457
|
-
"suiteDone",
|
458
|
-
"specStarted",
|
459
1232
|
"specDone"
|
460
1233
|
]);
|
461
1234
|
|
@@ -478,11 +1251,186 @@ describe("Env integration", function() {
|
|
478
1251
|
});
|
479
1252
|
|
480
1253
|
env.it("without a custom tester", function() {
|
481
|
-
env.expect("a").toContain("b");
|
1254
|
+
env.expect(["a"]).toContain("b");
|
482
1255
|
});
|
483
1256
|
});
|
484
1257
|
|
485
1258
|
env.execute();
|
486
1259
|
});
|
487
|
-
});
|
488
1260
|
|
1261
|
+
it("produces an understandable error message when an 'expect' is used outside of a current spec", function(done) {
|
1262
|
+
var env = new j$.Env();
|
1263
|
+
|
1264
|
+
env.describe("A Suite", function() {
|
1265
|
+
env.it("an async spec that is actually synchronous", function(underTestCallback) {
|
1266
|
+
underTestCallback();
|
1267
|
+
expect(function() { env.expect('a').toEqual('a'); }).toThrowError(/'expect' was used when there was no current spec/);
|
1268
|
+
done();
|
1269
|
+
});
|
1270
|
+
});
|
1271
|
+
|
1272
|
+
env.execute();
|
1273
|
+
});
|
1274
|
+
|
1275
|
+
it("Custom equality testers for toContain should be per suite", function(done) {
|
1276
|
+
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
1277
|
+
reporter = jasmine.createSpyObj('fakeReporter', [
|
1278
|
+
"jasmineDone",
|
1279
|
+
"specDone"
|
1280
|
+
]);
|
1281
|
+
|
1282
|
+
reporter.jasmineDone.and.callFake(function() {
|
1283
|
+
var firstSpecResult = reporter.specDone.calls.first().args[0],
|
1284
|
+
secondSpecResult = reporter.specDone.calls.argsFor(1)[0],
|
1285
|
+
thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];
|
1286
|
+
|
1287
|
+
expect(firstSpecResult.status).toEqual("passed");
|
1288
|
+
expect(secondSpecResult.status).toEqual("passed");
|
1289
|
+
expect(thirdSpecResult.status).toEqual("failed");
|
1290
|
+
|
1291
|
+
done();
|
1292
|
+
});
|
1293
|
+
|
1294
|
+
env.addReporter(reporter);
|
1295
|
+
|
1296
|
+
env.describe("testing custom equality testers", function() {
|
1297
|
+
env.beforeAll(function() { env.addCustomEqualityTester(function(a, b) { return true; })});
|
1298
|
+
|
1299
|
+
env.it("with a custom tester", function() {
|
1300
|
+
env.expect(["a"]).toContain("b");
|
1301
|
+
});
|
1302
|
+
|
1303
|
+
env.it("also with the custom tester", function() {
|
1304
|
+
env.expect(["a"]).toContain("b");
|
1305
|
+
});
|
1306
|
+
});
|
1307
|
+
|
1308
|
+
env.describe("another suite", function() {
|
1309
|
+
env.it("without the custom tester", function() {
|
1310
|
+
env.expect(["a"]).toContain("b");
|
1311
|
+
});
|
1312
|
+
});
|
1313
|
+
|
1314
|
+
env.execute();
|
1315
|
+
});
|
1316
|
+
|
1317
|
+
it("Custom matchers should be per spec", function(done) {
|
1318
|
+
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
1319
|
+
matchers = {
|
1320
|
+
toFoo: function() {}
|
1321
|
+
};
|
1322
|
+
|
1323
|
+
env.describe("testing custom matchers", function() {
|
1324
|
+
env.it("with a custom matcher", function() {
|
1325
|
+
env.addMatchers(matchers);
|
1326
|
+
expect(env.expect().toFoo).toBeDefined();
|
1327
|
+
});
|
1328
|
+
|
1329
|
+
env.it("without a custom matcher", function() {
|
1330
|
+
expect(env.expect().toFoo).toBeUndefined();
|
1331
|
+
});
|
1332
|
+
});
|
1333
|
+
|
1334
|
+
env.addReporter({jasmineDone: done});
|
1335
|
+
|
1336
|
+
env.execute();
|
1337
|
+
});
|
1338
|
+
|
1339
|
+
it("Custom matchers should be per suite", function(done) {
|
1340
|
+
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
1341
|
+
matchers = {
|
1342
|
+
toFoo: function() {}
|
1343
|
+
};
|
1344
|
+
|
1345
|
+
env.describe("testing custom matchers", function() {
|
1346
|
+
env.beforeAll(function() { env.addMatchers(matchers); });
|
1347
|
+
|
1348
|
+
env.it("with a custom matcher", function() {
|
1349
|
+
expect(env.expect().toFoo).toBeDefined();
|
1350
|
+
});
|
1351
|
+
|
1352
|
+
env.it("with the same custom matcher", function() {
|
1353
|
+
expect(env.expect().toFoo).toBeDefined();
|
1354
|
+
});
|
1355
|
+
});
|
1356
|
+
|
1357
|
+
env.describe("another suite", function() {
|
1358
|
+
env.it("no longer has the custom matcher", function() {
|
1359
|
+
expect(env.expect().toFoo).not.toBeDefined();
|
1360
|
+
});
|
1361
|
+
});
|
1362
|
+
|
1363
|
+
env.addReporter({jasmineDone: done});
|
1364
|
+
|
1365
|
+
env.execute();
|
1366
|
+
});
|
1367
|
+
|
1368
|
+
it('throws an exception if you try to create a spy outside of a runnable', function (done) {
|
1369
|
+
var env = new j$.Env(),
|
1370
|
+
obj = {fn: function () {}},
|
1371
|
+
exception;
|
1372
|
+
|
1373
|
+
env.describe("a suite", function () {
|
1374
|
+
try {
|
1375
|
+
env.spyOn(obj, 'fn');
|
1376
|
+
} catch(e) {
|
1377
|
+
exception = e;
|
1378
|
+
}
|
1379
|
+
});
|
1380
|
+
|
1381
|
+
var assertions = function() {
|
1382
|
+
expect(exception.message).toBe('Spies must be created in a before function or a spec');
|
1383
|
+
done();
|
1384
|
+
};
|
1385
|
+
|
1386
|
+
env.addReporter({jasmineDone: assertions});
|
1387
|
+
|
1388
|
+
env.execute();
|
1389
|
+
});
|
1390
|
+
|
1391
|
+
it('throws an exception if you try to add a matcher outside of a runnable', function (done) {
|
1392
|
+
var env = new j$.Env(),
|
1393
|
+
obj = {fn: function () {}},
|
1394
|
+
exception;
|
1395
|
+
|
1396
|
+
env.describe("a suite", function () {
|
1397
|
+
try {
|
1398
|
+
env.addMatchers({myMatcher: function(actual,expected){return false;}});
|
1399
|
+
} catch(e) {
|
1400
|
+
exception = e;
|
1401
|
+
}
|
1402
|
+
});
|
1403
|
+
|
1404
|
+
var assertions = function() {
|
1405
|
+
expect(exception.message).toBe('Matchers must be added in a before function or a spec');
|
1406
|
+
done();
|
1407
|
+
};
|
1408
|
+
|
1409
|
+
env.addReporter({jasmineDone: assertions});
|
1410
|
+
|
1411
|
+
env.execute();
|
1412
|
+
});
|
1413
|
+
|
1414
|
+
it('throws an exception if you try to add a custom equality outside of a runnable', function (done) {
|
1415
|
+
var env = new j$.Env(),
|
1416
|
+
obj = {fn: function () {}},
|
1417
|
+
exception;
|
1418
|
+
|
1419
|
+
env.describe("a suite", function () {
|
1420
|
+
try {
|
1421
|
+
env.addCustomEqualityTester(function(first, second) {return true;});
|
1422
|
+
} catch(e) {
|
1423
|
+
exception = e;
|
1424
|
+
}
|
1425
|
+
});
|
1426
|
+
|
1427
|
+
var assertions = function() {
|
1428
|
+
expect(exception.message).toBe('Custom Equalities must be added in a before function or a spec');
|
1429
|
+
done();
|
1430
|
+
};
|
1431
|
+
|
1432
|
+
env.addReporter({jasmineDone: assertions});
|
1433
|
+
|
1434
|
+
env.execute();
|
1435
|
+
});
|
1436
|
+
});
|