jasmine-core 2.0.0.rc5 → 2.0.0

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.
@@ -33,13 +33,13 @@ describe("Env", function() {
33
33
  });
34
34
 
35
35
  describe("#spyOn", function() {
36
- it("checks for the existance of the object", function() {
36
+ it("checks for the existence of the object", function() {
37
37
  expect(function() {
38
38
  env.spyOn(void 0, 'pants');
39
39
  }).toThrowError(/could not find an object/);
40
40
  });
41
41
 
42
- it("checks for the existance of the method", function() {
42
+ it("checks for the existence of the method", function() {
43
43
  var subject = {};
44
44
 
45
45
  expect(function() {
@@ -61,26 +61,9 @@ describe("Env", function() {
61
61
  var originalFunctionWasCalled = false;
62
62
  var subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
63
63
 
64
- originalFunc = subject.spiedFunc;
65
-
66
64
  var spy = env.spyOn(subject, 'spiedFunc');
67
65
 
68
66
  expect(subject.spiedFunc).toEqual(spy);
69
-
70
- expect(subject.spiedFunc.calls.any()).toEqual(false);
71
- expect(subject.spiedFunc.calls.count()).toEqual(0);
72
-
73
- subject.spiedFunc('foo');
74
-
75
- expect(subject.spiedFunc.calls.any()).toEqual(true);
76
- expect(subject.spiedFunc.calls.count()).toEqual(1);
77
- expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['foo']);
78
- expect(subject.spiedFunc.calls.mostRecent().object).toEqual(subject);
79
- expect(originalFunctionWasCalled).toEqual(false);
80
-
81
- subject.spiedFunc('bar');
82
- expect(subject.spiedFunc.calls.count()).toEqual(2);
83
- expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['bar']);
84
67
  });
85
68
  });
86
69
 
@@ -100,465 +83,3 @@ describe("Env", function() {
100
83
  });
101
84
  });
102
85
 
103
- // TODO: move these into a separate file
104
- describe("Env integration", function() {
105
-
106
- it("Suites execute as expected (no nesting)", function(done) {
107
- var env = new j$.Env(),
108
- calls = [];
109
-
110
- var assertions = function() {
111
- expect(calls).toEqual([
112
- "with a spec",
113
- "and another spec"
114
- ]);
115
-
116
- done();
117
- };
118
-
119
- env.addReporter({ jasmineDone: assertions});
120
-
121
- env.describe("A Suite", function() {
122
- env.it("with a spec", function() {
123
- calls.push("with a spec");
124
- });
125
- env.it("and another spec", function() {
126
- calls.push("and another spec");
127
- });
128
- });
129
-
130
- env.execute();
131
- });
132
-
133
- it("Nested Suites execute as expected", function(done) {
134
- var env = new j$.Env(),
135
- calls = [];
136
-
137
- var assertions = function() {
138
- expect(calls).toEqual([
139
- 'an outer spec',
140
- 'an inner spec',
141
- 'another inner spec'
142
- ]);
143
-
144
- done();
145
- };
146
-
147
- env.addReporter({ jasmineDone: assertions });
148
-
149
- env.describe("Outer suite", function() {
150
- env.it("an outer spec", function() {
151
- calls.push('an outer spec')
152
- });
153
- env.describe("Inner suite", function() {
154
- env.it("an inner spec", function() {
155
- calls.push('an inner spec');
156
- });
157
- env.it("another inner spec", function() {
158
- calls.push('another inner spec');
159
- });
160
- });
161
- });
162
-
163
- env.execute();
164
- });
165
-
166
- it("Multiple top-level Suites execute as expected", function(done) {
167
- var env = new j$.Env(),
168
- calls = [];
169
-
170
- var assertions = function() {
171
- expect(calls).toEqual([
172
- 'an outer spec',
173
- 'an inner spec',
174
- 'another inner spec',
175
- 'a 2nd outer spec'
176
- ]);
177
-
178
- done();
179
- };
180
-
181
- env.addReporter({ jasmineDone: assertions });
182
-
183
-
184
- env.describe("Outer suite", function() {
185
- env.it("an outer spec", function() {
186
- calls.push('an outer spec')
187
- });
188
- env.describe("Inner suite", function() {
189
- env.it("an inner spec", function() {
190
- calls.push('an inner spec');
191
- });
192
- env.it("another inner spec", function() {
193
- calls.push('another inner spec');
194
- });
195
- });
196
- });
197
-
198
- env.describe("Another outer suite", function() {
199
- env.it("a 2nd outer spec", function() {
200
- calls.push('a 2nd outer spec')
201
- });
202
- });
203
-
204
- env.execute();
205
- });
206
-
207
- it("calls associated befores/specs/afters with the same 'this'", function(done) {
208
- var env = new j$.Env();
209
-
210
- env.addReporter({jasmineDone: done});
211
-
212
- env.describe("tests", function() {
213
- var firstTimeThrough = true, firstSpecContext, secondSpecContext;
214
-
215
- env.beforeEach(function() {
216
- if (firstTimeThrough) {
217
- firstSpecContext = this;
218
- } else {
219
- secondSpecContext = this;
220
- }
221
- expect(this).toEqual({});
222
- });
223
-
224
- env.it("sync spec", function() {
225
- expect(this).toBe(firstSpecContext);
226
- });
227
-
228
- env.it("another sync spec", function() {
229
- expect(this).toBe(secondSpecContext);
230
- });
231
-
232
- env.afterEach(function() {
233
- if (firstTimeThrough) {
234
- expect(this).toBe(firstSpecContext);
235
- firstTimeThrough = false;
236
- } else {
237
- expect(this).toBe(secondSpecContext);
238
- }
239
- });
240
- });
241
-
242
- env.execute();
243
- });
244
-
245
- it("calls associated befores/its/afters with the same 'this' for an async spec", function(done) {
246
- var env = new j$.Env();
247
-
248
- env.addReporter({jasmineDone: done});
249
-
250
- env.describe("with an async spec", function() {
251
- var specContext;
252
-
253
- env.beforeEach(function() {
254
- specContext = this;
255
- expect(this).toEqual({});
256
- });
257
-
258
- env.it("sync spec", function(underTestCallback) {
259
- expect(this).toBe(specContext);
260
- underTestCallback();
261
- });
262
-
263
- env.afterEach(function() {
264
- expect(this).toBe(specContext);
265
- });
266
- });
267
-
268
- env.execute();
269
- });
270
-
271
- it("Allows specifying which specs and suites to run", function(done) {
272
- var env = new j$.Env(),
273
- calls = [],
274
- suiteCallback = jasmine.createSpy('suite callback'),
275
- firstSpec,
276
- secondSuite;
277
-
278
- var assertions = function() {
279
- expect(calls).toEqual([
280
- 'third spec',
281
- 'first spec'
282
- ]);
283
- expect(suiteCallback).toHaveBeenCalled();
284
- done();
285
- };
286
-
287
- env.addReporter({jasmineDone: assertions, suiteDone: suiteCallback});
288
-
289
- env.describe("first suite", function() {
290
- firstSpec = env.it("first spec", function() {
291
- calls.push('first spec');
292
- });
293
- env.it("second spec", function() {
294
- calls.push('second spec');
295
- });
296
- });
297
-
298
- secondSuite = env.describe("second suite", function() {
299
- env.it("third spec", function() {
300
- calls.push('third spec');
301
- });
302
- });
303
-
304
- env.execute([secondSuite.id, firstSpec.id]);
305
- });
306
-
307
- it("Mock clock can be installed and used in tests", function(done) {
308
- var globalSetTimeout = jasmine.createSpy('globalSetTimeout'),
309
- delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'),
310
- delayedFunctionForMockClock = jasmine.createSpy('delayedFunctionForMockClock'),
311
- env = new j$.Env({global: { setTimeout: globalSetTimeout }});
312
-
313
- var assertions = function() {
314
- expect(delayedFunctionForMockClock).toHaveBeenCalled();
315
- expect(globalSetTimeout).toHaveBeenCalledWith(delayedFunctionForGlobalClock, 100);
316
-
317
- done();
318
- };
319
-
320
- env.addReporter({ jasmineDone: assertions });
321
-
322
- env.describe("tests", function() {
323
- env.it("test with mock clock", function() {
324
- env.clock.install();
325
- env.clock.setTimeout(delayedFunctionForMockClock, 100);
326
- env.clock.tick(100);
327
- env.clock.uninstall();
328
- });
329
- env.it("test without mock clock", function() {
330
- env.clock.setTimeout(delayedFunctionForGlobalClock, 100);
331
- });
332
- });
333
-
334
- expect(globalSetTimeout).not.toHaveBeenCalled();
335
- expect(delayedFunctionForMockClock).not.toHaveBeenCalled();
336
-
337
- env.execute();
338
- });
339
-
340
- it("should run async specs in order, waiting for them to complete", function(done) {
341
- var env = new j$.Env(), mutatedVar;
342
-
343
- env.describe("tests", function() {
344
- env.beforeEach(function() {
345
- mutatedVar = 2;
346
- });
347
-
348
- env.it("async spec", function(underTestCallback) {
349
- setTimeout(function() {
350
- expect(mutatedVar).toEqual(2);
351
- underTestCallback();
352
- done();
353
- }, 0);
354
- });
355
-
356
- env.it("after async spec", function() {
357
- mutatedVar = 3;
358
- });
359
- });
360
-
361
- env.execute();
362
- });
363
-
364
- describe("with a mock clock", function() {
365
- var originalTimeout;
366
-
367
- beforeEach(function() {
368
- originalTimeout = j$.DEFAULT_TIMEOUT_INTERVAL;
369
- jasmine.getEnv().clock.install();
370
- });
371
-
372
- afterEach(function() {
373
- jasmine.getEnv().clock.uninstall();
374
- j$.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
375
- });
376
-
377
- it("should wait a specified interval before failing specs haven't called done yet", function(done) {
378
- var env = new j$.Env(),
379
- reporter = jasmine.createSpyObj('fakeReporter', [ "specDone" ]);
380
-
381
- reporter.specDone.and.callFake(function() {
382
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({status: 'failed'}));
383
- done();
384
- });
385
-
386
- env.addReporter(reporter);
387
- j$.DEFAULT_TIMEOUT_INTERVAL = 8414;
388
-
389
- env.it("async spec that doesn't call done", function(underTestCallback) {
390
- env.expect(true).toBeTruthy();
391
- jasmine.getEnv().clock.tick(8414);
392
- });
393
-
394
- env.execute();
395
- });
396
- });
397
-
398
- // TODO: something is wrong with this spec
399
- it("should report as expected", function(done) {
400
- var env = new j$.Env(),
401
- reporter = jasmine.createSpyObj('fakeReporter', [
402
- "jasmineStarted",
403
- "jasmineDone",
404
- "suiteStarted",
405
- "suiteDone",
406
- "specStarted",
407
- "specDone"
408
- ]);
409
-
410
- reporter.jasmineDone.and.callFake(function() {
411
- expect(reporter.jasmineStarted).toHaveBeenCalledWith({
412
- totalSpecsDefined: 3
413
- });
414
- var suiteResult = reporter.suiteStarted.calls.first().args[0];
415
- expect(suiteResult.description).toEqual("A Suite");
416
-
417
- done();
418
- });
419
-
420
- env.addReporter(reporter);
421
-
422
- env.describe("A Suite", function() {
423
- env.it("with a top level spec", function() {
424
- env.expect(true).toBe(true);
425
- });
426
- env.describe("with a nested suite", function() {
427
- env.xit("with a pending spec", function() {
428
- env.expect(true).toBe(true);
429
- });
430
- env.it("with a spec", function() {
431
- env.expect(true).toBe(false);
432
- });
433
- });
434
- });
435
-
436
- env.execute();
437
- });
438
-
439
- it("should be possible to get full name from a spec", function() {
440
- var env = new j$.Env({global: { setTimeout: setTimeout }}),
441
- topLevelSpec, nestedSpec, doublyNestedSpec;
442
-
443
- env.describe("my tests", function() {
444
- topLevelSpec = env.it("are sometimes top level", function() {
445
- });
446
- env.describe("are sometimes", function() {
447
- nestedSpec = env.it("singly nested", function() {
448
- });
449
- env.describe("even", function() {
450
- doublyNestedSpec = env.it("doubly nested", function() {
451
- });
452
- });
453
- });
454
- });
455
-
456
- expect(topLevelSpec.getFullName()).toBe("my tests are sometimes top level");
457
- expect(nestedSpec.getFullName()).toBe("my tests are sometimes singly nested");
458
- expect(doublyNestedSpec.getFullName()).toBe("my tests are sometimes even doubly nested");
459
- });
460
-
461
- it("Custom equality testers should be per spec", function(done) {
462
- var env = new j$.Env({global: { setTimeout: setTimeout }}),
463
- reporter = jasmine.createSpyObj('fakeReproter', [
464
- "jasmineStarted",
465
- "jasmineDone",
466
- "suiteStarted",
467
- "suiteDone",
468
- "specStarted",
469
- "specDone"
470
- ]);
471
-
472
- reporter.jasmineDone.and.callFake(function() {
473
- var firstSpecResult = reporter.specDone.calls.first().args[0],
474
- secondSpecResult = reporter.specDone.calls.mostRecent().args[0];
475
-
476
- expect(firstSpecResult.status).toEqual("passed");
477
- expect(secondSpecResult.status).toEqual("failed");
478
-
479
- done();
480
- });
481
-
482
- env.addReporter(reporter);
483
-
484
- env.describe("testing custom equality testers", function() {
485
- env.it("with a custom tester", function() {
486
- env.addCustomEqualityTester(function(a, b) { return true; });
487
- env.expect("a").toEqual("b");
488
- });
489
-
490
- env.it("without a custom tester", function() {
491
- env.expect("a").toEqual("b");
492
- });
493
- });
494
-
495
- env.execute();
496
- });
497
-
498
- it("Custom matchers should be per spec", function() {
499
- var env = new j$.Env({global: { setTimeout: setTimeout }}),
500
- matchers = {
501
- toFoo: function() {}
502
- },
503
- reporter = jasmine.createSpyObj('fakeReproter', [
504
- "jasmineStarted",
505
- "jasmineDone",
506
- "suiteStarted",
507
- "suiteDone",
508
- "specStarted",
509
- "specDone"
510
- ]);
511
-
512
- env.addReporter(reporter);
513
-
514
- env.describe("testing custom matchers", function() {
515
- env.it("with a custom matcher", function() {
516
- env.addMatchers(matchers);
517
- expect(env.expect().toFoo).toBeDefined();
518
- });
519
-
520
- env.it("without a custom matcher", function() {
521
- expect(env.expect().toFoo).toBeUndefined();
522
- });
523
- });
524
-
525
- env.execute();
526
- });
527
-
528
- it("Custom equality testers for toContain should be per spec", function(done) {
529
- var env = new j$.Env({global: { setTimeout: setTimeout }}),
530
- reporter = jasmine.createSpyObj('fakeReproter', [
531
- "jasmineStarted",
532
- "jasmineDone",
533
- "suiteStarted",
534
- "suiteDone",
535
- "specStarted",
536
- "specDone"
537
- ]);
538
-
539
- reporter.jasmineDone.and.callFake(function() {
540
- var firstSpecResult = reporter.specDone.calls.first().args[0],
541
- secondSpecResult = reporter.specDone.calls.mostRecent().args[0];
542
-
543
- expect(firstSpecResult.status).toEqual("passed");
544
- expect(secondSpecResult.status).toEqual("failed");
545
-
546
- done();
547
- });
548
-
549
- env.addReporter(reporter);
550
-
551
- env.describe("testing custom equality testers", function() {
552
- env.it("with a custom tester", function() {
553
- env.addCustomEqualityTester(function(a, b) { return true; });
554
- env.expect(["a"]).toContain("b");
555
- });
556
-
557
- env.it("without a custom tester", function() {
558
- env.expect("a").toContain("b");
559
- });
560
- });
561
-
562
- env.execute();
563
- });
564
- });