jasmine-core 2.0.0.rc2 → 2.0.0.rc3

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.
Files changed (30) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jasmine-core/boot.js +0 -4
  3. data/lib/jasmine-core/boot/boot.js +0 -4
  4. data/lib/jasmine-core/jasmine-html.js +3 -1
  5. data/lib/jasmine-core/jasmine.css +4 -3
  6. data/lib/jasmine-core/jasmine.js +64 -34
  7. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +2 -2
  8. data/lib/jasmine-core/spec/core/ClockSpec.js +168 -118
  9. data/lib/jasmine-core/spec/core/EnvSpec.js +133 -48
  10. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +1 -1
  11. data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +2 -2
  12. data/lib/jasmine-core/spec/core/ExpectationSpec.js +2 -2
  13. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +1 -1
  14. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +17 -0
  15. data/lib/jasmine-core/spec/core/SpecRunningSpec.js +6 -6
  16. data/lib/jasmine-core/spec/core/SpecSpec.js +6 -2
  17. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +19 -9
  18. data/lib/jasmine-core/spec/core/TimerSpec.js +2 -2
  19. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +2 -2
  20. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +2 -2
  21. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +7 -12
  22. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +8 -8
  23. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +4 -4
  24. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +15 -11
  25. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +5 -3
  26. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +7 -0
  27. data/lib/jasmine-core/spec/node_suite.js +1 -1
  28. data/lib/jasmine-core/spec/support/dev_boot.js +0 -5
  29. data/lib/jasmine-core/version.rb +1 -1
  30. metadata +16 -107
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1bd31139a1c91448e7da9a70a0d2305d03b2d0bc
4
+ data.tar.gz: 6f9500edfc06f08901eb9899ced10cf6fe331c70
5
+ SHA512:
6
+ metadata.gz: 1abbaef73d3e0be63149fec07fba134017274b54aa7b7339b6422266b250387b947bf06ce4952d85a344f5cb85e21f527b90d1d505840c079fbed46b4a2020ac
7
+ data.tar.gz: 814477470ab35ce9d86a96c11f92a10d54600e88bbfa95de2e7527961ccb459371399374d9aa503b2dc3713857a9bcd1d90437b0cd45ec03b9ac07b4fdedc7b2
@@ -69,10 +69,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
69
69
  },
70
70
 
71
71
  clock: env.clock,
72
- setTimeout: env.clock.setTimeout,
73
- clearTimeout: env.clock.clearTimeout,
74
- setInterval: env.clock.setInterval,
75
- clearInterval: env.clock.clearInterval,
76
72
  jsApiReporter: new jasmine.JsApiReporter({
77
73
  timer: new jasmine.Timer()
78
74
  })
@@ -47,10 +47,6 @@
47
47
  },
48
48
 
49
49
  clock: env.clock,
50
- setTimeout: env.clock.setTimeout,
51
- clearTimeout: env.clock.clearTimeout,
52
- setInterval: env.clock.setInterval,
53
- clearInterval: env.clock.clearInterval,
54
50
  jsApiReporter: new jasmine.JsApiReporter({
55
51
  timer: new jasmine.Timer()
56
52
  })
@@ -109,7 +109,9 @@ jasmineRequire.HtmlReporter = function(j$) {
109
109
 
110
110
  var failure =
111
111
  createDom("div", {className: "spec-detail failed"},
112
- createDom("a", {className: "description", title: result.fullName, href: specHref(result)}, result.fullName),
112
+ createDom("div", {className: "description"},
113
+ createDom("a", {title: result.fullName, href: specHref(result)}, result.fullName)
114
+ ),
113
115
  createDom("div", {className: "messages"})
114
116
  );
115
117
  var messages = failure.childNodes[1];
@@ -11,7 +11,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
11
11
  .html-reporter .banner { margin-top: 14px; }
12
12
  .html-reporter .duration { color: #aaaaaa; float: right; }
13
13
  .html-reporter .symbol-summary { overflow: hidden; *zoom: 1; margin: 14px 0; }
14
- .html-reporter .symbol-summary li { display: block; float: left; height: 7px; width: 14px; margin-bottom: 7px; font-size: 16px; }
14
+ .html-reporter .symbol-summary li { display: inline-block; height: 8px; width: 14px; font-size: 16px; }
15
15
  .html-reporter .symbol-summary li.passed { font-size: 14px; }
16
16
  .html-reporter .symbol-summary li.passed:before { color: #5e7d00; content: "\02022"; }
17
17
  .html-reporter .symbol-summary li.failed { line-height: 9px; }
@@ -48,7 +48,8 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
48
48
  .html-reporter .suite { margin-top: 14px; }
49
49
  .html-reporter .suite a { color: #333333; }
50
50
  .html-reporter .failures .spec-detail { margin-bottom: 28px; }
51
- .html-reporter .failures .spec-detail .description { display: block; color: white; background-color: #b03911; }
51
+ .html-reporter .failures .spec-detail .description { background-color: #b03911; }
52
+ .html-reporter .failures .spec-detail .description a { color: white; }
52
53
  .html-reporter .result-message { padding-top: 14px; color: #333333; white-space: pre; }
53
54
  .html-reporter .result-message span.result { display: block; }
54
- .html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #dddddd; background: white; white-space: pre; }
55
+ .html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; }
@@ -30,7 +30,7 @@ function getJasmineRequireObj() {
30
30
  }
31
31
 
32
32
  getJasmineRequireObj().core = function(jRequire) {
33
- j$ = {};
33
+ var j$ = {};
34
34
 
35
35
  jRequire.base(j$);
36
36
  j$.util = jRequire.util();
@@ -48,7 +48,7 @@ getJasmineRequireObj().core = function(jRequire) {
48
48
  j$.pp = jRequire.pp(j$);
49
49
  j$.QueueRunner = jRequire.QueueRunner();
50
50
  j$.ReportDispatcher = jRequire.ReportDispatcher();
51
- j$.Spec = jRequire.Spec();
51
+ j$.Spec = jRequire.Spec(j$);
52
52
  j$.SpyStrategy = jRequire.SpyStrategy();
53
53
  j$.Suite = jRequire.Suite();
54
54
  j$.Timer = jRequire.Timer();
@@ -94,7 +94,6 @@ getJasmineRequireObj().base = function(j$) {
94
94
  throw new Error("unimplemented method");
95
95
  };
96
96
 
97
- j$.DEFAULT_UPDATE_INTERVAL = 250;
98
97
  j$.MAX_PRETTY_PRINT_DEPTH = 40;
99
98
  j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
100
99
 
@@ -221,7 +220,7 @@ getJasmineRequireObj().util = function() {
221
220
  return util;
222
221
  };
223
222
 
224
- getJasmineRequireObj().Spec = function() {
223
+ getJasmineRequireObj().Spec = function(j$) {
225
224
  function Spec(attrs) {
226
225
  this.encounteredExpectations = false;
227
226
  this.expectationFactory = attrs.expectationFactory;
@@ -281,14 +280,14 @@ getJasmineRequireObj().Spec = function() {
281
280
  var timeout = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
282
281
  onException(new Error('timeout'));
283
282
  done();
284
- }, 10000]]);
283
+ }, j$.DEFAULT_TIMEOUT_INTERVAL]]);
285
284
 
286
285
  var callDone = function() {
287
286
  Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeout]]);
288
287
  done();
289
288
  };
290
289
 
291
- fn(callDone); //TODO: do we care about more than 1 arg?
290
+ fn.call(this, callDone); //TODO: do we care about more than 1 arg?
292
291
  };
293
292
  }
294
293
 
@@ -382,6 +381,8 @@ getJasmineRequireObj().Env = function(j$) {
382
381
  var realClearTimeout = j$.getGlobal().clearTimeout;
383
382
  this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler());
384
383
 
384
+ var runnableLookupTable = {};
385
+
385
386
  var spies = [];
386
387
 
387
388
  this.currentSpec = null;
@@ -450,7 +451,7 @@ getJasmineRequireObj().Env = function(j$) {
450
451
  };
451
452
 
452
453
  var getSpecName = function(spec, currentSuite) {
453
- return currentSuite.getFullName() + ' ' + spec.description + '.';
454
+ return currentSuite.getFullName() + ' ' + spec.description;
454
455
  };
455
456
 
456
457
  // TODO: we may just be able to pass in the fn instead of wrapping here
@@ -519,6 +520,8 @@ getJasmineRequireObj().Env = function(j$) {
519
520
  timer: {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}
520
521
  });
521
522
 
523
+ runnableLookupTable[spec.id] = spec;
524
+
522
525
  if (!self.specFilter(spec)) {
523
526
  spec.disable();
524
527
  }
@@ -557,10 +560,11 @@ getJasmineRequireObj().Env = function(j$) {
557
560
  completeCallback: function() {}, // TODO - hook this up
558
561
  resultCallback: function() {} // TODO - hook this up
559
562
  });
563
+ runnableLookupTable[this.topSuite.id] = this.topSuite;
560
564
  this.currentSuite = this.topSuite;
561
565
 
562
566
  this.suiteFactory = function(description) {
563
- return new suiteConstructor({
567
+ var suite = new suiteConstructor({
564
568
  env: self,
565
569
  id: self.nextSuiteId(),
566
570
  description: description,
@@ -571,13 +575,25 @@ getJasmineRequireObj().Env = function(j$) {
571
575
  self.reporter.suiteDone(attrs);
572
576
  }
573
577
  });
578
+
579
+ runnableLookupTable[suite.id] = suite;
580
+ return suite;
574
581
  };
575
582
 
576
- this.execute = function() {
583
+ this.execute = function(runnablesToRun) {
584
+ runnablesToRun = runnablesToRun || [this.topSuite.id];
585
+
586
+ var allFns = [];
587
+ for(var i = 0; i < runnablesToRun.length; i++) {
588
+ var runnable = runnableLookupTable[runnablesToRun[i]];
589
+ allFns.push((function(runnable) { return function(done) { runnable.execute(done); }; })(runnable));
590
+ }
591
+
577
592
  this.reporter.jasmineStarted({
578
593
  totalSpecsDefined: totalSpecsDefined
579
594
  });
580
- this.topSuite.execute(self.reporter.jasmineDone);
595
+
596
+ queueRunnerFactory({fns: allFns, onComplete: this.reporter.jasmineDone});
581
597
  };
582
598
 
583
599
  this.spyOn = function(obj, methodName) {
@@ -630,12 +646,12 @@ getJasmineRequireObj().Env = function(j$) {
630
646
 
631
647
  // TODO: move this to closure
632
648
  Env.prototype.nextSpecId = function() {
633
- return this.nextSpecId_++;
649
+ return 'spec' + this.nextSpecId_++;
634
650
  };
635
651
 
636
652
  // TODO: move this to closure
637
653
  Env.prototype.nextSuiteId = function() {
638
- return this.nextSuiteId_++;
654
+ return 'suite' + this.nextSuiteId_++;
639
655
  };
640
656
 
641
657
  // TODO: move this to closure
@@ -889,18 +905,19 @@ getJasmineRequireObj().Clock = function() {
889
905
  setInterval: setInterval,
890
906
  clearInterval: clearInterval
891
907
  },
892
- timer = realTimingFunctions,
893
908
  installed = false;
894
909
 
895
910
  self.install = function() {
896
- installed = true;
911
+ replace(global, fakeTimingFunctions);
897
912
  timer = fakeTimingFunctions;
913
+ installed = true;
898
914
  };
899
915
 
900
916
  self.uninstall = function() {
901
917
  delayedFunctionScheduler.reset();
902
- installed = false;
918
+ replace(global, realTimingFunctions);
903
919
  timer = realTimingFunctions;
920
+ installed = false;
904
921
  };
905
922
 
906
923
  self.setTimeout = function(fn, delay, params) {
@@ -935,7 +952,7 @@ getJasmineRequireObj().Clock = function() {
935
952
  if (installed) {
936
953
  delayedFunctionScheduler.tick(millis);
937
954
  } else {
938
- throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
955
+ throw new Error("Mock clock is not installed, use jasmine.getEnv().clock.install()");
939
956
  }
940
957
  };
941
958
 
@@ -945,7 +962,13 @@ getJasmineRequireObj().Clock = function() {
945
962
  //if these methods are polyfilled, apply will be present
946
963
  //TODO: it may be difficult to load the polyfill before jasmine loads
947
964
  //(env should be new-ed inside of onload)
948
- return !(global.setTimeout || global.setInterval).apply;
965
+ return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply;
966
+ }
967
+
968
+ function replace(dest, source) {
969
+ for (var prop in source) {
970
+ dest[prop] = source[prop];
971
+ }
949
972
  }
950
973
 
951
974
  function setTimeout(fn, delay) {
@@ -981,8 +1004,8 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
981
1004
 
982
1005
  self.tick = function(millis) {
983
1006
  millis = millis || 0;
984
- runFunctionsWithinRange(currentTime, currentTime + millis);
985
1007
  currentTime = currentTime + millis;
1008
+ runFunctionsWithinRange(currentTime - millis, currentTime);
986
1009
  };
987
1010
 
988
1011
  self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) {
@@ -1323,7 +1346,7 @@ getJasmineRequireObj().pp = function(j$) {
1323
1346
  this.emitScalar('Date(' + value + ')');
1324
1347
  } else if (value.__Jasmine_been_here_before__) {
1325
1348
  this.emitScalar('<circular reference: ' + (j$.isArray_(value) ? 'Array' : 'Object') + '>');
1326
- } else if (j$.isArray_(value) || typeof value == 'object') {
1349
+ } else if (j$.isArray_(value) || j$.isA_('Object', value)) {
1327
1350
  value.__Jasmine_been_here_before__ = true;
1328
1351
  if (j$.isArray_(value)) {
1329
1352
  this.emitArray(value);
@@ -1433,6 +1456,7 @@ getJasmineRequireObj().QueueRunner = function() {
1433
1456
  this.clearStack = attrs.clearStack || function(fn) {fn();};
1434
1457
  this.onException = attrs.onException || function() {};
1435
1458
  this.catchException = attrs.catchException || function() { return true; };
1459
+ this.userContext = {};
1436
1460
  }
1437
1461
 
1438
1462
  QueueRunner.prototype.execute = function() {
@@ -1461,7 +1485,7 @@ getJasmineRequireObj().QueueRunner = function() {
1461
1485
 
1462
1486
  function attemptSync(fn) {
1463
1487
  try {
1464
- fn.call(self);
1488
+ fn.call(self.userContext);
1465
1489
  } catch (e) {
1466
1490
  handleException(e);
1467
1491
  }
@@ -1471,7 +1495,7 @@ getJasmineRequireObj().QueueRunner = function() {
1471
1495
  var next = function () { self.run(fns, iterativeIndex + 1); };
1472
1496
 
1473
1497
  try {
1474
- fn.call(self, next);
1498
+ fn.call(self.userContext, next);
1475
1499
  } catch (e) {
1476
1500
  handleException(e);
1477
1501
  next();
@@ -1550,16 +1574,17 @@ getJasmineRequireObj().SpyStrategy = function() {
1550
1574
  return getSpy();
1551
1575
  };
1552
1576
 
1553
- this.callReturn = function(value) {
1577
+ this.returnValue = function(value) {
1554
1578
  plan = function() {
1555
1579
  return value;
1556
1580
  };
1557
1581
  return getSpy();
1558
1582
  };
1559
1583
 
1560
- this.callThrow = function(something) {
1584
+ this.throwError = function(something) {
1585
+ var error = (something instanceof Error) ? something : new Error(something);
1561
1586
  plan = function() {
1562
- throw something;
1587
+ throw error;
1563
1588
  };
1564
1589
  return getSpy();
1565
1590
  };
@@ -2114,21 +2139,26 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
2114
2139
  compare: function() {
2115
2140
  var args = Array.prototype.slice.call(arguments, 0),
2116
2141
  actual = args[0],
2117
- expectedArgs = args.slice(1);
2142
+ expectedArgs = args.slice(1),
2143
+ result = { pass: false };
2118
2144
 
2119
2145
  if (!j$.isSpy(actual)) {
2120
2146
  throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.');
2121
2147
  }
2122
2148
 
2123
- return {
2124
- pass: util.contains(actual.calls.allArgs(), expectedArgs)
2125
- };
2126
- },
2127
- message: function(actual) {
2128
- return {
2129
- affirmative: "Expected spy " + actual.and.identity() + " to have been called.",
2130
- negative: "Expected spy " + actual.and.identity() + " not to have been called."
2131
- };
2149
+ if (!actual.calls.any()) {
2150
+ result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but it was never called.";
2151
+ return result;
2152
+ }
2153
+
2154
+ if (util.contains(actual.calls.allArgs(), expectedArgs)) {
2155
+ result.pass = true;
2156
+ result.message = "Expected spy " + actual.and.identity() + " not to have been called with " + j$.pp(expectedArgs) + " but it was.";
2157
+ } else {
2158
+ result.message = "Expected spy " + actual.and.identity() + " to have been called with " + j$.pp(expectedArgs) + " but actual calls were " + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + ".";
2159
+ }
2160
+
2161
+ return result;
2132
2162
  }
2133
2163
  };
2134
2164
  }
@@ -90,7 +90,7 @@ describe("ConsoleReporter", function() {
90
90
  reporter.jasmineStarted();
91
91
  reporter.specDone({status: "passed"});
92
92
 
93
- timerSpy.elapsed.and.callReturn(1000);
93
+ timerSpy.elapsed.and.returnValue(1000);
94
94
 
95
95
  out.clear();
96
96
  reporter.jasmineDone();
@@ -127,7 +127,7 @@ describe("ConsoleReporter", function() {
127
127
 
128
128
  out.clear();
129
129
 
130
- timerSpy.elapsed.and.callReturn(100);
130
+ timerSpy.elapsed.and.returnValue(100);
131
131
 
132
132
  reporter.jasmineDone();
133
133
 
@@ -1,41 +1,141 @@
1
1
  describe("Clock", function() {
2
2
 
3
- it("calls the global setTimeout directly if Clock is not installed", function() {
4
- var setTimeout = jasmine.createSpy('setTimeout'),
5
- delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['scheduleFunction']),
6
- global = { setTimeout: setTimeout },
7
- delayedFn = jasmine.createSpy('delayedFn'),
8
- clock = new j$.Clock(global, delayedFunctionScheduler);
3
+ it("does not replace setTimeout until it is installed", function() {
4
+ var fakeSetTimeout = jasmine.createSpy("global setTimeout"),
5
+ fakeGlobal = { setTimeout: fakeSetTimeout },
6
+ delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
7
+ delayedFn = jasmine.createSpy("delayedFn"),
8
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
9
9
 
10
- clock.setTimeout(delayedFn, 0);
10
+ fakeGlobal.setTimeout(delayedFn, 0);
11
11
 
12
+ expect(fakeSetTimeout).toHaveBeenCalledWith(delayedFn, 0);
12
13
  expect(delayedFunctionScheduler.scheduleFunction).not.toHaveBeenCalled();
13
- expect(setTimeout).toHaveBeenCalledWith(delayedFn, 0);
14
+
15
+ fakeSetTimeout.calls.reset();
16
+
17
+ clock.install();
18
+ fakeGlobal.setTimeout(delayedFn, 0);
19
+
20
+ expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalled();
21
+ expect(fakeSetTimeout).not.toHaveBeenCalled();
14
22
  });
15
23
 
16
- it("schedules the delayed function with the fake timer", function() {
17
- var setTimeout = jasmine.createSpy('setTimeout'),
24
+ it("does not replace clearTimeout until it is installed", function() {
25
+ var fakeClearTimeout = jasmine.createSpy("global cleartimeout"),
26
+ fakeGlobal = { clearTimeout: fakeClearTimeout },
27
+ delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
28
+ delayedFn = jasmine.createSpy("delayedFn"),
29
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
30
+
31
+ fakeGlobal.clearTimeout("foo");
32
+
33
+ expect(fakeClearTimeout).toHaveBeenCalledWith("foo");
34
+ expect(delayedFunctionScheduler.removeFunctionWithId).not.toHaveBeenCalled();
35
+
36
+ fakeClearTimeout.calls.reset();
37
+
38
+ clock.install();
39
+ fakeGlobal.clearTimeout("foo");
40
+
41
+ expect(delayedFunctionScheduler.removeFunctionWithId).toHaveBeenCalled();
42
+ expect(fakeClearTimeout).not.toHaveBeenCalled();
43
+ });
44
+
45
+ it("does not replace setInterval until it is installed", function() {
46
+ var fakeSetInterval = jasmine.createSpy("global setInterval"),
47
+ fakeGlobal = { setInterval: fakeSetInterval },
48
+ delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
49
+ delayedFn = jasmine.createSpy("delayedFn"),
50
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
51
+
52
+ fakeGlobal.setInterval(delayedFn, 0);
53
+
54
+ expect(fakeSetInterval).toHaveBeenCalledWith(delayedFn, 0);
55
+ expect(delayedFunctionScheduler.scheduleFunction).not.toHaveBeenCalled();
56
+
57
+ fakeSetInterval.calls.reset();
58
+
59
+ clock.install();
60
+ fakeGlobal.setInterval(delayedFn, 0);
61
+
62
+ expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalled();
63
+ expect(fakeSetInterval).not.toHaveBeenCalled();
64
+ });
65
+
66
+ it("does not replace clearInterval until it is installed", function() {
67
+ var fakeClearInterval = jasmine.createSpy("global clearinterval"),
68
+ fakeGlobal = { clearInterval: fakeClearInterval },
69
+ delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
70
+ delayedFn = jasmine.createSpy("delayedFn"),
71
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
72
+
73
+ fakeGlobal.clearInterval("foo");
74
+
75
+ expect(fakeClearInterval).toHaveBeenCalledWith("foo");
76
+ expect(delayedFunctionScheduler.removeFunctionWithId).not.toHaveBeenCalled();
77
+
78
+ fakeClearInterval.calls.reset();
79
+
80
+ clock.install();
81
+ fakeGlobal.clearInterval("foo");
82
+
83
+ expect(delayedFunctionScheduler.removeFunctionWithId).toHaveBeenCalled();
84
+ expect(fakeClearInterval).not.toHaveBeenCalled();
85
+ });
86
+
87
+ it("replaces the global timer functions on uninstall", function() {
88
+ var fakeSetTimeout = jasmine.createSpy("global setTimeout"),
89
+ fakeClearTimeout = jasmine.createSpy("global clearTimeout"),
90
+ fakeSetInterval = jasmine.createSpy("global setInterval"),
91
+ fakeClearInterval = jasmine.createSpy("global clearInterval"),
92
+ fakeGlobal = {
93
+ setTimeout: fakeSetTimeout,
94
+ clearTimeout: fakeClearTimeout,
95
+ setInterval: fakeSetInterval,
96
+ clearInterval: fakeClearInterval
97
+ },
98
+ delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset"]),
99
+ delayedFn = jasmine.createSpy("delayedFn"),
100
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
101
+
102
+ clock.install();
103
+ clock.uninstall();
104
+ fakeGlobal.setTimeout(delayedFn, 0);
105
+ fakeGlobal.clearTimeout("foo");
106
+ fakeGlobal.setInterval(delayedFn, 10);
107
+ fakeGlobal.clearInterval("bar");
108
+
109
+ expect(fakeSetTimeout).toHaveBeenCalledWith(delayedFn, 0);
110
+ expect(fakeClearTimeout).toHaveBeenCalledWith("foo");
111
+ expect(fakeSetInterval).toHaveBeenCalledWith(delayedFn, 10);
112
+ expect(fakeClearInterval).toHaveBeenCalledWith("bar");
113
+ expect(delayedFunctionScheduler.scheduleFunction).not.toHaveBeenCalled();
114
+ });
115
+
116
+ it("schedules the delayed function (via setTimeout) with the fake timer", function() {
117
+ var fakeSetTimeout = jasmine.createSpy('setTimeout'),
18
118
  scheduleFunction = jasmine.createSpy('scheduleFunction'),
19
- delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
20
- global = { setTimeout: setTimeout },
119
+ delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
120
+ fakeGlobal = { setTimeout: fakeSetTimeout },
21
121
  delayedFn = jasmine.createSpy('delayedFn'),
22
- clock = new j$.Clock(global, delayedFunctionScheduler);
122
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
23
123
 
24
124
  clock.install();
25
125
  clock.setTimeout(delayedFn, 0, 'a', 'b');
26
126
 
27
- expect(setTimeout).not.toHaveBeenCalled();
127
+ expect(fakeSetTimeout).not.toHaveBeenCalled();
28
128
  expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b']);
29
129
  });
30
130
 
31
131
  it("returns an id for the delayed function", function() {
32
- var setTimeout = jasmine.createSpy('setTimeout'),
132
+ var fakeSetTimeout = jasmine.createSpy('setTimeout'),
33
133
  scheduleId = 123,
34
- scheduleFunction = jasmine.createSpy('scheduleFunction').and.callReturn(scheduleId),
134
+ scheduleFunction = jasmine.createSpy('scheduleFunction').and.returnValue(scheduleId),
35
135
  delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
36
- global = { setTimeout: setTimeout },
136
+ fakeGlobal = { setTimeout: fakeSetTimeout },
37
137
  delayedFn = jasmine.createSpy('delayedFn'),
38
- clock = new j$.Clock(global, delayedFunctionScheduler),
138
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler),
39
139
  timeoutId;
40
140
 
41
141
  clock.install();
@@ -44,67 +144,43 @@ describe("Clock", function() {
44
144
  expect(timeoutId).toEqual(123);
45
145
  });
46
146
 
47
- it("calls the global clearTimeout directly if Clock is not installed", function() {
48
- var clearTimeout = jasmine.createSpy('clearTimeout'),
49
- delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['clearTimeout']),
50
- global = { clearTimeout: clearTimeout },
51
- clock = new j$.Clock(global, delayedFunctionScheduler);
52
-
53
- clock.clearTimeout(123);
54
-
55
- expect(clearTimeout).toHaveBeenCalledWith(123);
56
- });
57
-
58
147
  it("clears the scheduled function with the scheduler", function() {
59
- var clearTimeout = jasmine.createSpy('clearTimeout'),
148
+ var fakeClearTimeout = jasmine.createSpy('clearTimeout'),
60
149
  delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['removeFunctionWithId']),
61
- global = { setTimeout: clearTimeout },
150
+ fakeGlobal = { setTimeout: fakeClearTimeout },
62
151
  delayedFn = jasmine.createSpy('delayedFn'),
63
- clock = new j$.Clock(global, delayedFunctionScheduler);
152
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
64
153
 
65
154
  clock.install();
66
155
  clock.clearTimeout(123);
67
156
 
68
- expect(clearTimeout).not.toHaveBeenCalled();
157
+ expect(fakeClearTimeout).not.toHaveBeenCalled();
69
158
  expect(delayedFunctionScheduler.removeFunctionWithId).toHaveBeenCalledWith(123);
70
159
  });
71
160
 
72
- it("calls the global setInterval directly if Clock is not installed", function() {
73
- var setInterval = jasmine.createSpy('setInterval'),
74
- delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['scheduleFunction']),
75
- global = { setInterval: setInterval },
76
- delayedFn = jasmine.createSpy('delayedFn'),
77
- clock = new j$.Clock(global, delayedFunctionScheduler);
78
-
79
- clock.setInterval(delayedFn, 0);
80
-
81
- expect(delayedFunctionScheduler.scheduleFunction).not.toHaveBeenCalled();
82
- expect(setInterval).toHaveBeenCalledWith(delayedFn, 0);
83
- });
84
-
85
161
  it("schedules the delayed function with the fake timer", function() {
86
- var setInterval = jasmine.createSpy('setInterval'),
162
+ var fakeSetInterval = jasmine.createSpy('setInterval'),
87
163
  scheduleFunction = jasmine.createSpy('scheduleFunction'),
88
164
  delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
89
- global = { setInterval: setInterval },
165
+ fakeGlobal = { setInterval: fakeSetInterval },
90
166
  delayedFn = jasmine.createSpy('delayedFn'),
91
- clock = new j$.Clock(global, delayedFunctionScheduler);
167
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
92
168
 
93
169
  clock.install();
94
170
  clock.setInterval(delayedFn, 0, 'a', 'b');
95
171
 
96
- expect(setInterval).not.toHaveBeenCalled();
172
+ expect(fakeSetInterval).not.toHaveBeenCalled();
97
173
  expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b'], true);
98
174
  });
99
175
 
100
176
  it("returns an id for the delayed function", function() {
101
- var setInterval = jasmine.createSpy('setInterval'),
177
+ var fakeSetInterval = jasmine.createSpy('setInterval'),
102
178
  scheduleId = 123,
103
- scheduleFunction = jasmine.createSpy('scheduleFunction').and.callReturn(scheduleId),
179
+ scheduleFunction = jasmine.createSpy('scheduleFunction').and.returnValue(scheduleId),
104
180
  delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
105
- global = { setInterval: setInterval },
181
+ fakeGlobal = { setInterval: fakeSetInterval },
106
182
  delayedFn = jasmine.createSpy('delayedFn'),
107
- clock = new j$.Clock(global, delayedFunctionScheduler),
183
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler),
108
184
  intervalId;
109
185
 
110
186
  clock.install();
@@ -113,23 +189,12 @@ describe("Clock", function() {
113
189
  expect(intervalId).toEqual(123);
114
190
  });
115
191
 
116
- it("calls the global clearInterval directly if Clock is not installed", function() {
117
- var clearInterval = jasmine.createSpy('clearInterval'),
118
- delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['clearInterval']),
119
- global = { clearInterval: clearInterval },
120
- clock = new j$.Clock(global, delayedFunctionScheduler);
121
-
122
- clock.clearInterval(123);
123
-
124
- expect(clearInterval).toHaveBeenCalledWith(123);
125
- });
126
-
127
192
  it("clears the scheduled function with the scheduler", function() {
128
193
  var clearInterval = jasmine.createSpy('clearInterval'),
129
194
  delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['removeFunctionWithId']),
130
- global = { setInterval: clearInterval },
195
+ fakeGlobal = { setInterval: clearInterval },
131
196
  delayedFn = jasmine.createSpy('delayedFn'),
132
- clock = new j$.Clock(global, delayedFunctionScheduler);
197
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
133
198
 
134
199
  clock.install();
135
200
  clock.clearInterval(123);
@@ -145,53 +210,20 @@ describe("Clock", function() {
145
210
  }).toThrow();
146
211
  });
147
212
 
148
- it("can be uninstalled", function() {
149
- var setTimeout = jasmine.createSpy('setTimeout'),
150
- setInterval = jasmine.createSpy('setInterval'),
151
- delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['scheduleFunction', 'tick', 'reset']),
152
- global = { setTimeout: setTimeout, setInterval: setInterval },
153
- delayedFn = jasmine.createSpy('delayedFn'),
154
- clock = new j$.Clock(global, delayedFunctionScheduler);
155
-
156
- clock.install();
157
- clock.setTimeout(delayedFn, 0);
158
- expect(setTimeout).not.toHaveBeenCalled();
159
-
160
- clock.setInterval(delayedFn, 0);
161
- expect(setInterval).not.toHaveBeenCalled();
162
-
163
- expect(function() {
164
- clock.tick(0);
165
- }).not.toThrow();
166
-
167
- clock.uninstall();
168
-
169
- expect(delayedFunctionScheduler.reset).toHaveBeenCalled();
170
-
171
- clock.setTimeout(delayedFn, 0);
172
-
173
- expect(setTimeout).toHaveBeenCalled();
174
-
175
- clock.setInterval(delayedFn, 0);
176
- expect(setInterval).toHaveBeenCalled();
177
-
178
- expect(function() {
179
- clock.tick(0);
180
- }).toThrow();
181
- });
182
-
183
-
184
213
  it("on IE < 9, fails if extra args are passed to fake clock", function() {
185
214
  //fail, because this would break in IE9.
186
- var setTimeout = jasmine.createSpy('setTimeout'),
187
- setInterval = jasmine.createSpy('setInterval'),
188
- delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['scheduleFunction']),
189
- fn = jasmine.createSpy('fn'),
190
- global = { setTimeout: setTimeout, setInterval: setInterval },
191
- clock = new j$.Clock(global, delayedFunctionScheduler);
215
+ var fakeSetTimeout = jasmine.createSpy('setTimeout'),
216
+ fakeSetInterval = jasmine.createSpy('setInterval'),
217
+ delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['scheduleFunction']),
218
+ fn = jasmine.createSpy('fn'),
219
+ fakeGlobal = {
220
+ setTimeout: fakeSetTimeout,
221
+ setInterval: fakeSetInterval
222
+ },
223
+ clock = new j$.Clock(fakeGlobal, delayedFunctionScheduler);
192
224
 
193
- setTimeout.apply = null;
194
- setInterval.apply = null;
225
+ fakeSetTimeout.apply = null;
226
+ fakeSetInterval.apply = null;
195
227
 
196
228
  clock.install();
197
229
 
@@ -221,8 +253,8 @@ describe("Clock (acceptance)", function() {
221
253
 
222
254
  clock.install();
223
255
 
224
- clock.setTimeout(delayedFn1, 0, 'some', 'arg');
225
- var intervalId = clock.setInterval(recurring1, 50, 'some', 'other', 'args');
256
+ clock.setTimeout(delayedFn1, 0);
257
+ var intervalId = clock.setInterval(recurring1, 50);
226
258
  clock.setTimeout(delayedFn2, 100);
227
259
  clock.setTimeout(delayedFn3, 200);
228
260
 
@@ -232,13 +264,13 @@ describe("Clock (acceptance)", function() {
232
264
 
233
265
  clock.tick(0);
234
266
 
235
- expect(delayedFn1).toHaveBeenCalledWith('some', 'arg');
267
+ expect(delayedFn1).toHaveBeenCalled();
236
268
  expect(delayedFn2).not.toHaveBeenCalled();
237
269
  expect(delayedFn3).not.toHaveBeenCalled();
238
270
 
239
271
  clock.tick(50);
240
272
 
241
- expect(recurring1).toHaveBeenCalledWith('some', 'other', 'args');
273
+ expect(recurring1).toHaveBeenCalled();
242
274
  expect(recurring1.calls.count()).toBe(1);
243
275
  expect(delayedFn2).not.toHaveBeenCalled();
244
276
  expect(delayedFn3).not.toHaveBeenCalled();
@@ -280,7 +312,7 @@ describe("Clock (acceptance)", function() {
280
312
  it("correctly schedules functions after the Clock has advanced", function() {
281
313
  var delayedFn1 = jasmine.createSpy('delayedFn1'),
282
314
  delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
283
- clock = new j$.Clock({setTimeout: function(){}}, delayedFunctionScheduler);
315
+ clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler);
284
316
 
285
317
  clock.install();
286
318
 
@@ -292,7 +324,25 @@ describe("Clock (acceptance)", function() {
292
324
  expect(delayedFn1).toHaveBeenCalled();
293
325
  });
294
326
 
295
- it("calls the global clearTimeout correctly when not installed", function () {
327
+ it("correctly schedules functions while the Clock is advancing", function() {
328
+ var delayedFn1 = jasmine.createSpy('delayedFn1'),
329
+ delayedFn2 = jasmine.createSpy('delayedFn2'),
330
+ delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
331
+ clock = new j$.Clock({setTimeout: function() {}}, delayedFunctionScheduler);
332
+
333
+ delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 0); });
334
+ clock.install();
335
+ clock.setTimeout(delayedFn1, 5);
336
+
337
+ clock.tick(5);
338
+ expect(delayedFn1).toHaveBeenCalled();
339
+ expect(delayedFn2).not.toHaveBeenCalled();
340
+
341
+ clock.tick();
342
+ expect(delayedFn2).toHaveBeenCalled();
343
+ });
344
+
345
+ it("calls the global clearTimeout correctly when not installed", function() {
296
346
  var delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['clearTimeout']),
297
347
  global = jasmine.getGlobal(),
298
348
  clock = new j$.Clock(global, delayedFunctionScheduler);
@@ -302,7 +352,7 @@ describe("Clock (acceptance)", function() {
302
352
  }).not.toThrow();
303
353
  });
304
354
 
305
- it("calls the global clearTimeout correctly when not installed", function () {
355
+ it("calls the global clearTimeout correctly when not installed", function() {
306
356
  var delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['clearTimeout']),
307
357
  global = jasmine.getGlobal(),
308
358
  clock = new j$.Clock(global, delayedFunctionScheduler);