jasmine-core 2.9.0 → 2.99.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jasmine-core/jasmine-html.js +24 -1
- data/lib/jasmine-core/jasmine.css +1 -0
- data/lib/jasmine-core/jasmine.js +50 -6
- data/lib/jasmine-core/version.rb +1 -1
- metadata +3 -84
- data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +0 -270
- data/lib/jasmine-core/spec/core/CallTrackerSpec.js +0 -130
- data/lib/jasmine-core/spec/core/ClearStackSpec.js +0 -137
- data/lib/jasmine-core/spec/core/ClockSpec.js +0 -754
- data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +0 -270
- data/lib/jasmine-core/spec/core/EnvSpec.js +0 -200
- data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +0 -63
- data/lib/jasmine-core/spec/core/ExceptionsSpec.js +0 -68
- data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +0 -61
- data/lib/jasmine-core/spec/core/ExpectationSpec.js +0 -434
- data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +0 -110
- data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +0 -259
- data/lib/jasmine-core/spec/core/MockDateSpec.js +0 -200
- data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +0 -337
- data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +0 -620
- data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +0 -79
- data/lib/jasmine-core/spec/core/SpecSpec.js +0 -441
- data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +0 -356
- data/lib/jasmine-core/spec/core/SpySpec.js +0 -127
- data/lib/jasmine-core/spec/core/SpyStrategySpec.js +0 -159
- data/lib/jasmine-core/spec/core/SuiteSpec.js +0 -155
- data/lib/jasmine-core/spec/core/TimerSpec.js +0 -31
- data/lib/jasmine-core/spec/core/TreeProcessorSpec.js +0 -756
- data/lib/jasmine-core/spec/core/UserContextSpec.js +0 -54
- data/lib/jasmine-core/spec/core/UtilSpec.js +0 -99
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +0 -84
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +0 -76
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +0 -52
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +0 -47
- data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +0 -102
- data/lib/jasmine-core/spec/core/asymmetric_equality/StringMatchingSpec.js +0 -27
- data/lib/jasmine-core/spec/core/formatErrorMsgSpec.js +0 -13
- data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +0 -199
- data/lib/jasmine-core/spec/core/integration/EnvSpec.js +0 -2007
- data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +0 -950
- data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +0 -47
- data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +0 -13
- data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +0 -43
- data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +0 -658
- data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +0 -8
- data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +0 -93
- data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +0 -18
- data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +0 -38
- data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanOrEqualSpec.js +0 -29
- data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +0 -20
- data/lib/jasmine-core/spec/core/matchers/toBeLessThanOrEqualSpec.js +0 -29
- data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +0 -20
- data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +0 -37
- data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +0 -31
- data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +0 -17
- data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +0 -31
- data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +0 -17
- data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +0 -38
- data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +0 -18
- data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +0 -26
- data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +0 -804
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +0 -99
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +0 -47
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledTimesSpec.js +0 -86
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +0 -67
- data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +0 -43
- data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +0 -315
- data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +0 -100
- data/lib/jasmine-core/spec/helpers/BrowserFlags.js +0 -27
- data/lib/jasmine-core/spec/helpers/asyncAwait.js +0 -27
- data/lib/jasmine-core/spec/helpers/checkForMap.js +0 -37
- data/lib/jasmine-core/spec/helpers/checkForSet.js +0 -41
- data/lib/jasmine-core/spec/helpers/checkForSymbol.js +0 -28
- data/lib/jasmine-core/spec/helpers/checkForTypedArrays.js +0 -20
- data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +0 -7
- data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +0 -33
- data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +0 -982
- data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +0 -18
- data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +0 -37
- data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +0 -15
- data/lib/jasmine-core/spec/html/QueryStringSpec.js +0 -72
- data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +0 -62
- data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +0 -34
- data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +0 -101
- data/lib/jasmine-core/spec/performance/large_object_test.js +0 -36
- data/lib/jasmine-core/spec/performance/performance_test.js +0 -10
@@ -1,754 +0,0 @@
|
|
1
|
-
describe("Clock", function() {
|
2
|
-
|
3
|
-
var NODE_JS = typeof process !== 'undefined' && process.versions && typeof process.versions.node === 'string';
|
4
|
-
|
5
|
-
it("does not replace setTimeout until it is installed", function() {
|
6
|
-
var fakeSetTimeout = jasmine.createSpy("global setTimeout"),
|
7
|
-
fakeGlobal = { setTimeout: fakeSetTimeout },
|
8
|
-
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
|
9
|
-
delayedFn = jasmine.createSpy("delayedFn"),
|
10
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
11
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
12
|
-
|
13
|
-
fakeGlobal.setTimeout(delayedFn, 0);
|
14
|
-
|
15
|
-
expect(fakeSetTimeout).toHaveBeenCalledWith(delayedFn, 0);
|
16
|
-
expect(delayedFunctionScheduler.scheduleFunction).not.toHaveBeenCalled();
|
17
|
-
|
18
|
-
fakeSetTimeout.calls.reset();
|
19
|
-
|
20
|
-
clock.install();
|
21
|
-
fakeGlobal.setTimeout(delayedFn, 0);
|
22
|
-
|
23
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalled();
|
24
|
-
expect(fakeSetTimeout).not.toHaveBeenCalled();
|
25
|
-
});
|
26
|
-
|
27
|
-
it("does not replace clearTimeout until it is installed", function() {
|
28
|
-
var fakeClearTimeout = jasmine.createSpy("global cleartimeout"),
|
29
|
-
fakeGlobal = { clearTimeout: fakeClearTimeout },
|
30
|
-
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
|
31
|
-
delayedFn = jasmine.createSpy("delayedFn"),
|
32
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
33
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
34
|
-
|
35
|
-
fakeGlobal.clearTimeout("foo");
|
36
|
-
|
37
|
-
expect(fakeClearTimeout).toHaveBeenCalledWith("foo");
|
38
|
-
expect(delayedFunctionScheduler.removeFunctionWithId).not.toHaveBeenCalled();
|
39
|
-
|
40
|
-
fakeClearTimeout.calls.reset();
|
41
|
-
|
42
|
-
clock.install();
|
43
|
-
fakeGlobal.clearTimeout("foo");
|
44
|
-
|
45
|
-
expect(delayedFunctionScheduler.removeFunctionWithId).toHaveBeenCalled();
|
46
|
-
expect(fakeClearTimeout).not.toHaveBeenCalled();
|
47
|
-
});
|
48
|
-
|
49
|
-
it("does not replace setInterval until it is installed", function() {
|
50
|
-
var fakeSetInterval = jasmine.createSpy("global setInterval"),
|
51
|
-
fakeGlobal = { setInterval: fakeSetInterval },
|
52
|
-
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
|
53
|
-
delayedFn = jasmine.createSpy("delayedFn"),
|
54
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
55
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
56
|
-
|
57
|
-
fakeGlobal.setInterval(delayedFn, 0);
|
58
|
-
|
59
|
-
expect(fakeSetInterval).toHaveBeenCalledWith(delayedFn, 0);
|
60
|
-
expect(delayedFunctionScheduler.scheduleFunction).not.toHaveBeenCalled();
|
61
|
-
|
62
|
-
fakeSetInterval.calls.reset();
|
63
|
-
|
64
|
-
clock.install();
|
65
|
-
fakeGlobal.setInterval(delayedFn, 0);
|
66
|
-
|
67
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalled();
|
68
|
-
expect(fakeSetInterval).not.toHaveBeenCalled();
|
69
|
-
});
|
70
|
-
|
71
|
-
it("does not replace clearInterval until it is installed", function() {
|
72
|
-
var fakeClearInterval = jasmine.createSpy("global clearinterval"),
|
73
|
-
fakeGlobal = { clearInterval: fakeClearInterval },
|
74
|
-
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
|
75
|
-
delayedFn = jasmine.createSpy("delayedFn"),
|
76
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
77
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
78
|
-
|
79
|
-
fakeGlobal.clearInterval("foo");
|
80
|
-
|
81
|
-
expect(fakeClearInterval).toHaveBeenCalledWith("foo");
|
82
|
-
expect(delayedFunctionScheduler.removeFunctionWithId).not.toHaveBeenCalled();
|
83
|
-
|
84
|
-
fakeClearInterval.calls.reset();
|
85
|
-
|
86
|
-
clock.install();
|
87
|
-
fakeGlobal.clearInterval("foo");
|
88
|
-
|
89
|
-
expect(delayedFunctionScheduler.removeFunctionWithId).toHaveBeenCalled();
|
90
|
-
expect(fakeClearInterval).not.toHaveBeenCalled();
|
91
|
-
});
|
92
|
-
|
93
|
-
it("does not install if the current setTimeout is not the original function on the global", function() {
|
94
|
-
var originalFakeSetTimeout = function() {},
|
95
|
-
replacedSetTimeout = function() {},
|
96
|
-
fakeGlobal = { setTimeout: originalFakeSetTimeout },
|
97
|
-
delayedFunctionSchedulerFactory = jasmine.createSpy('delayedFunctionSchedulerFactory'),
|
98
|
-
mockDate = {},
|
99
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
|
100
|
-
|
101
|
-
fakeGlobal.setTimeout = replacedSetTimeout;
|
102
|
-
|
103
|
-
expect(function() {
|
104
|
-
clock.install();
|
105
|
-
}).toThrowError(/unable to install/);
|
106
|
-
|
107
|
-
expect(delayedFunctionSchedulerFactory).not.toHaveBeenCalled();
|
108
|
-
expect(fakeGlobal.setTimeout).toBe(replacedSetTimeout);
|
109
|
-
});
|
110
|
-
|
111
|
-
it("does not install if the current clearTimeout is not the original function on the global", function() {
|
112
|
-
var originalFakeClearTimeout = function() {},
|
113
|
-
replacedClearTimeout = function() {},
|
114
|
-
fakeGlobal = { clearTimeout: originalFakeClearTimeout },
|
115
|
-
delayedFunctionSchedulerFactory = jasmine.createSpy('delayedFunctionSchedulerFactory'),
|
116
|
-
mockDate = {},
|
117
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
|
118
|
-
|
119
|
-
fakeGlobal.clearTimeout = replacedClearTimeout;
|
120
|
-
|
121
|
-
expect(function() {
|
122
|
-
clock.install();
|
123
|
-
}).toThrowError(/unable to install/);
|
124
|
-
|
125
|
-
expect(delayedFunctionSchedulerFactory).not.toHaveBeenCalled();
|
126
|
-
expect(fakeGlobal.clearTimeout).toBe(replacedClearTimeout);
|
127
|
-
});
|
128
|
-
|
129
|
-
it("does not install if the current setInterval is not the original function on the global", function() {
|
130
|
-
var originalFakeSetInterval = function() {},
|
131
|
-
replacedSetInterval = function() {},
|
132
|
-
fakeGlobal = { setInterval: originalFakeSetInterval },
|
133
|
-
delayedFunctionSchedulerFactory = jasmine.createSpy('delayedFunctionSchedulerFactory'),
|
134
|
-
mockDate = {},
|
135
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
|
136
|
-
|
137
|
-
fakeGlobal.setInterval = replacedSetInterval;
|
138
|
-
|
139
|
-
expect(function() {
|
140
|
-
clock.install();
|
141
|
-
}).toThrowError(/unable to install/);
|
142
|
-
|
143
|
-
expect(delayedFunctionSchedulerFactory).not.toHaveBeenCalled();
|
144
|
-
expect(fakeGlobal.setInterval).toBe(replacedSetInterval);
|
145
|
-
});
|
146
|
-
|
147
|
-
it("does not install if the current clearInterval is not the original function on the global", function() {
|
148
|
-
var originalFakeClearInterval = function() {},
|
149
|
-
replacedClearInterval = function() {},
|
150
|
-
fakeGlobal = { clearInterval: originalFakeClearInterval },
|
151
|
-
delayedFunctionSchedulerFactory = jasmine.createSpy('delayedFunctionSchedulerFactory'),
|
152
|
-
mockDate = {},
|
153
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
|
154
|
-
|
155
|
-
fakeGlobal.clearInterval = replacedClearInterval;
|
156
|
-
|
157
|
-
expect(function() {
|
158
|
-
clock.install();
|
159
|
-
}).toThrowError(/unable to install/);
|
160
|
-
|
161
|
-
expect(delayedFunctionSchedulerFactory).not.toHaveBeenCalled();
|
162
|
-
expect(fakeGlobal.clearInterval).toBe(replacedClearInterval);
|
163
|
-
});
|
164
|
-
|
165
|
-
it("replaces the global timer functions on uninstall", function() {
|
166
|
-
var fakeSetTimeout = jasmine.createSpy("global setTimeout"),
|
167
|
-
fakeClearTimeout = jasmine.createSpy("global clearTimeout"),
|
168
|
-
fakeSetInterval = jasmine.createSpy("global setInterval"),
|
169
|
-
fakeClearInterval = jasmine.createSpy("global clearInterval"),
|
170
|
-
fakeGlobal = {
|
171
|
-
setTimeout: fakeSetTimeout,
|
172
|
-
clearTimeout: fakeClearTimeout,
|
173
|
-
setInterval: fakeSetInterval,
|
174
|
-
clearInterval: fakeClearInterval
|
175
|
-
},
|
176
|
-
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset"]),
|
177
|
-
delayedFn = jasmine.createSpy("delayedFn"),
|
178
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
179
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
180
|
-
|
181
|
-
clock.install();
|
182
|
-
clock.uninstall();
|
183
|
-
fakeGlobal.setTimeout(delayedFn, 0);
|
184
|
-
fakeGlobal.clearTimeout("foo");
|
185
|
-
fakeGlobal.setInterval(delayedFn, 10);
|
186
|
-
fakeGlobal.clearInterval("bar");
|
187
|
-
|
188
|
-
expect(fakeSetTimeout).toHaveBeenCalledWith(delayedFn, 0);
|
189
|
-
expect(fakeClearTimeout).toHaveBeenCalledWith("foo");
|
190
|
-
expect(fakeSetInterval).toHaveBeenCalledWith(delayedFn, 10);
|
191
|
-
expect(fakeClearInterval).toHaveBeenCalledWith("bar");
|
192
|
-
expect(delayedFunctionScheduler.scheduleFunction).not.toHaveBeenCalled();
|
193
|
-
});
|
194
|
-
|
195
|
-
it("can be installed for the duration of a passed in function and uninstalled when done", function() {
|
196
|
-
var fakeSetTimeout = jasmine.createSpy("global setTimeout"),
|
197
|
-
fakeClearTimeout = jasmine.createSpy("global clearTimeout"),
|
198
|
-
fakeSetInterval = jasmine.createSpy("global setInterval"),
|
199
|
-
fakeClearInterval = jasmine.createSpy("global clearInterval"),
|
200
|
-
fakeGlobal = {
|
201
|
-
setTimeout: fakeSetTimeout,
|
202
|
-
clearTimeout: fakeClearTimeout,
|
203
|
-
setInterval: fakeSetInterval,
|
204
|
-
clearInterval: fakeClearInterval
|
205
|
-
},
|
206
|
-
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset", "removeFunctionWithId"]),
|
207
|
-
delayedFn = jasmine.createSpy("delayedFn"),
|
208
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
209
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
210
|
-
passedFunctionCalled = false;
|
211
|
-
|
212
|
-
clock.withMock(function() {
|
213
|
-
fakeGlobal.setTimeout(delayedFn, 0);
|
214
|
-
fakeGlobal.clearTimeout("foo");
|
215
|
-
fakeGlobal.setInterval(delayedFn, 10);
|
216
|
-
fakeGlobal.clearInterval("bar");
|
217
|
-
passedFunctionCalled = true;
|
218
|
-
});
|
219
|
-
|
220
|
-
expect(passedFunctionCalled).toBe(true);
|
221
|
-
|
222
|
-
expect(fakeSetTimeout).not.toHaveBeenCalled();
|
223
|
-
expect(fakeClearTimeout).not.toHaveBeenCalled();
|
224
|
-
expect(fakeSetInterval).not.toHaveBeenCalled();
|
225
|
-
expect(fakeClearInterval).not.toHaveBeenCalled();
|
226
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalled();
|
227
|
-
|
228
|
-
delayedFunctionScheduler.scheduleFunction.calls.reset();
|
229
|
-
|
230
|
-
fakeGlobal.setTimeout(delayedFn, 0);
|
231
|
-
fakeGlobal.clearTimeout("foo");
|
232
|
-
fakeGlobal.setInterval(delayedFn, 10);
|
233
|
-
fakeGlobal.clearInterval("bar");
|
234
|
-
|
235
|
-
expect(fakeSetTimeout).toHaveBeenCalledWith(delayedFn, 0);
|
236
|
-
expect(fakeClearTimeout).toHaveBeenCalledWith("foo");
|
237
|
-
expect(fakeSetInterval).toHaveBeenCalledWith(delayedFn, 10);
|
238
|
-
expect(fakeClearInterval).toHaveBeenCalledWith("bar");
|
239
|
-
expect(delayedFunctionScheduler.scheduleFunction).not.toHaveBeenCalled();
|
240
|
-
});
|
241
|
-
|
242
|
-
it("can be installed for the duration of a passed in function and uninstalled if an error is thrown", function() {
|
243
|
-
var fakeSetTimeout = jasmine.createSpy("global setTimeout"),
|
244
|
-
fakeClearTimeout = jasmine.createSpy("global clearTimeout"),
|
245
|
-
fakeSetInterval = jasmine.createSpy("global setInterval"),
|
246
|
-
fakeClearInterval = jasmine.createSpy("global clearInterval"),
|
247
|
-
fakeGlobal = {
|
248
|
-
setTimeout: fakeSetTimeout,
|
249
|
-
clearTimeout: fakeClearTimeout,
|
250
|
-
setInterval: fakeSetInterval,
|
251
|
-
clearInterval: fakeClearInterval
|
252
|
-
},
|
253
|
-
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset", "removeFunctionWithId"]),
|
254
|
-
delayedFn = jasmine.createSpy("delayedFn"),
|
255
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
256
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
257
|
-
passedFunctionCalled = false;
|
258
|
-
|
259
|
-
expect(function() {
|
260
|
-
clock.withMock(function() {
|
261
|
-
fakeGlobal.setTimeout(delayedFn, 0);
|
262
|
-
fakeGlobal.clearTimeout("foo");
|
263
|
-
fakeGlobal.setInterval(delayedFn, 10);
|
264
|
-
fakeGlobal.clearInterval("bar");
|
265
|
-
passedFunctionCalled = true;
|
266
|
-
throw 'oops';
|
267
|
-
});
|
268
|
-
}).toThrow('oops');
|
269
|
-
|
270
|
-
expect(passedFunctionCalled).toBe(true);
|
271
|
-
|
272
|
-
expect(fakeSetTimeout).not.toHaveBeenCalled();
|
273
|
-
expect(fakeClearTimeout).not.toHaveBeenCalled();
|
274
|
-
expect(fakeSetInterval).not.toHaveBeenCalled();
|
275
|
-
expect(fakeClearInterval).not.toHaveBeenCalled();
|
276
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalled();
|
277
|
-
|
278
|
-
delayedFunctionScheduler.scheduleFunction.calls.reset();
|
279
|
-
|
280
|
-
fakeGlobal.setTimeout(delayedFn, 0);
|
281
|
-
fakeGlobal.clearTimeout("foo");
|
282
|
-
fakeGlobal.setInterval(delayedFn, 10);
|
283
|
-
fakeGlobal.clearInterval("bar");
|
284
|
-
|
285
|
-
expect(fakeSetTimeout).toHaveBeenCalledWith(delayedFn, 0);
|
286
|
-
expect(fakeClearTimeout).toHaveBeenCalledWith("foo");
|
287
|
-
expect(fakeSetInterval).toHaveBeenCalledWith(delayedFn, 10);
|
288
|
-
expect(fakeClearInterval).toHaveBeenCalledWith("bar");
|
289
|
-
expect(delayedFunctionScheduler.scheduleFunction).not.toHaveBeenCalled();
|
290
|
-
});
|
291
|
-
|
292
|
-
it("schedules the delayed function (via setTimeout) with the fake timer", function() {
|
293
|
-
var fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
294
|
-
scheduleFunction = jasmine.createSpy('scheduleFunction'),
|
295
|
-
delayedFunctionScheduler = { scheduleFunction: scheduleFunction },
|
296
|
-
fakeGlobal = { setTimeout: fakeSetTimeout },
|
297
|
-
delayedFn = jasmine.createSpy('delayedFn'),
|
298
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
299
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
300
|
-
timeout = new clock.FakeTimeout();
|
301
|
-
|
302
|
-
clock.install();
|
303
|
-
clock.setTimeout(delayedFn, 0, 'a', 'b');
|
304
|
-
|
305
|
-
expect(fakeSetTimeout).not.toHaveBeenCalled();
|
306
|
-
|
307
|
-
if (!NODE_JS) {
|
308
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b']);
|
309
|
-
} else {
|
310
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b'], false, timeout);
|
311
|
-
}
|
312
|
-
});
|
313
|
-
|
314
|
-
it("returns an id for the delayed function", function() {
|
315
|
-
var fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
316
|
-
scheduleId = 123,
|
317
|
-
scheduleFunction = jasmine.createSpy('scheduleFunction').and.returnValue(scheduleId),
|
318
|
-
delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
|
319
|
-
fakeGlobal = { setTimeout: fakeSetTimeout },
|
320
|
-
delayedFn = jasmine.createSpy('delayedFn'),
|
321
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
322
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
323
|
-
timeout;
|
324
|
-
|
325
|
-
clock.install();
|
326
|
-
timeout = clock.setTimeout(delayedFn, 0);
|
327
|
-
|
328
|
-
if (!NODE_JS) {
|
329
|
-
expect(timeout).toEqual(123);
|
330
|
-
} else {
|
331
|
-
expect(timeout.constructor.name).toEqual('FakeTimeout');
|
332
|
-
}
|
333
|
-
});
|
334
|
-
|
335
|
-
it("clears the scheduled function with the scheduler", function() {
|
336
|
-
var fakeClearTimeout = jasmine.createSpy('clearTimeout'),
|
337
|
-
delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['removeFunctionWithId']),
|
338
|
-
fakeGlobal = { setTimeout: fakeClearTimeout },
|
339
|
-
delayedFn = jasmine.createSpy('delayedFn'),
|
340
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
341
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
342
|
-
|
343
|
-
clock.install();
|
344
|
-
clock.clearTimeout(123);
|
345
|
-
|
346
|
-
expect(fakeClearTimeout).not.toHaveBeenCalled();
|
347
|
-
expect(delayedFunctionScheduler.removeFunctionWithId).toHaveBeenCalledWith(123);
|
348
|
-
});
|
349
|
-
|
350
|
-
it("schedules the delayed function with the fake timer", function() {
|
351
|
-
var fakeSetInterval = jasmine.createSpy('setInterval'),
|
352
|
-
scheduleFunction = jasmine.createSpy('scheduleFunction'),
|
353
|
-
delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
|
354
|
-
fakeGlobal = { setInterval: fakeSetInterval },
|
355
|
-
delayedFn = jasmine.createSpy('delayedFn'),
|
356
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
357
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
358
|
-
timeout = new clock.FakeTimeout;
|
359
|
-
|
360
|
-
clock.install();
|
361
|
-
clock.setInterval(delayedFn, 0, 'a', 'b');
|
362
|
-
|
363
|
-
expect(fakeSetInterval).not.toHaveBeenCalled();
|
364
|
-
|
365
|
-
if (!NODE_JS) {
|
366
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b'], true);
|
367
|
-
} else {
|
368
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(delayedFn, 0, ['a', 'b'], true, timeout);
|
369
|
-
}
|
370
|
-
});
|
371
|
-
|
372
|
-
it("returns an id for the delayed function", function() {
|
373
|
-
var fakeSetInterval = jasmine.createSpy('setInterval'),
|
374
|
-
scheduleId = 123,
|
375
|
-
scheduleFunction = jasmine.createSpy('scheduleFunction').and.returnValue(scheduleId),
|
376
|
-
delayedFunctionScheduler = {scheduleFunction: scheduleFunction},
|
377
|
-
fakeGlobal = { setInterval: fakeSetInterval },
|
378
|
-
delayedFn = jasmine.createSpy('delayedFn'),
|
379
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
380
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
381
|
-
interval;
|
382
|
-
|
383
|
-
clock.install();
|
384
|
-
interval = clock.setInterval(delayedFn, 0);
|
385
|
-
|
386
|
-
if (!NODE_JS) {
|
387
|
-
expect(interval).toEqual(123);
|
388
|
-
} else {
|
389
|
-
expect(interval.constructor.name).toEqual('FakeTimeout');
|
390
|
-
}
|
391
|
-
});
|
392
|
-
|
393
|
-
it("clears the scheduled function with the scheduler", function() {
|
394
|
-
var clearInterval = jasmine.createSpy('clearInterval'),
|
395
|
-
delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['removeFunctionWithId']),
|
396
|
-
fakeGlobal = { setInterval: clearInterval },
|
397
|
-
delayedFn = jasmine.createSpy('delayedFn'),
|
398
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
399
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
|
400
|
-
|
401
|
-
clock.install();
|
402
|
-
clock.clearInterval(123);
|
403
|
-
|
404
|
-
expect(clearInterval).not.toHaveBeenCalled();
|
405
|
-
expect(delayedFunctionScheduler.removeFunctionWithId).toHaveBeenCalledWith(123);
|
406
|
-
});
|
407
|
-
|
408
|
-
it("gives you a friendly reminder if the Clock is not installed and you tick", function() {
|
409
|
-
var clock = new jasmineUnderTest.Clock({}, jasmine.createSpyObj('delayedFunctionScheduler', ['tick']));
|
410
|
-
expect(function() {
|
411
|
-
clock.tick(50);
|
412
|
-
}).toThrow();
|
413
|
-
});
|
414
|
-
|
415
|
-
it("on IE < 9, fails if extra args are passed to fake clock", function() {
|
416
|
-
//fail, because this would break in IE9.
|
417
|
-
var fakeSetTimeout = jasmine.createSpy('setTimeout'),
|
418
|
-
fakeSetInterval = jasmine.createSpy('setInterval'),
|
419
|
-
delayedFunctionScheduler = jasmine.createSpyObj('delayedFunctionScheduler', ['scheduleFunction']),
|
420
|
-
fn = jasmine.createSpy('fn'),
|
421
|
-
fakeGlobal = {
|
422
|
-
setTimeout: fakeSetTimeout,
|
423
|
-
setInterval: fakeSetInterval
|
424
|
-
},
|
425
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
426
|
-
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
|
427
|
-
timeout = new clock.FakeTimeout();
|
428
|
-
|
429
|
-
fakeSetTimeout.apply = null;
|
430
|
-
fakeSetInterval.apply = null;
|
431
|
-
|
432
|
-
clock.install();
|
433
|
-
|
434
|
-
clock.setTimeout(fn, 0);
|
435
|
-
|
436
|
-
if (!NODE_JS) {
|
437
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(fn, 0, []);
|
438
|
-
} else {
|
439
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(fn, 0, [], false, timeout);
|
440
|
-
}
|
441
|
-
|
442
|
-
expect(function() {
|
443
|
-
clock.setTimeout(fn, 0, 'extra');
|
444
|
-
}).toThrow();
|
445
|
-
|
446
|
-
clock.setInterval(fn, 0);
|
447
|
-
|
448
|
-
if (!NODE_JS) {
|
449
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(fn, 0, [], true);
|
450
|
-
} else {
|
451
|
-
expect(delayedFunctionScheduler.scheduleFunction).toHaveBeenCalledWith(fn, 0, [], true, timeout);
|
452
|
-
}
|
453
|
-
|
454
|
-
expect(function() {
|
455
|
-
clock.setInterval(fn, 0, 'extra');
|
456
|
-
}).toThrow();
|
457
|
-
});
|
458
|
-
});
|
459
|
-
|
460
|
-
describe("Clock (acceptance)", function() {
|
461
|
-
it("can run setTimeouts/setIntervals synchronously", function() {
|
462
|
-
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
463
|
-
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
464
|
-
delayedFn3 = jasmine.createSpy('delayedFn3'),
|
465
|
-
recurring1 = jasmine.createSpy('recurring1'),
|
466
|
-
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
467
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
468
|
-
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
|
469
|
-
|
470
|
-
clock.install();
|
471
|
-
|
472
|
-
clock.setTimeout(delayedFn1, 0);
|
473
|
-
var intervalId = clock.setInterval(recurring1, 50);
|
474
|
-
clock.setTimeout(delayedFn2, 100);
|
475
|
-
clock.setTimeout(delayedFn3, 200);
|
476
|
-
|
477
|
-
expect(delayedFn1).not.toHaveBeenCalled();
|
478
|
-
expect(delayedFn2).not.toHaveBeenCalled();
|
479
|
-
expect(delayedFn3).not.toHaveBeenCalled();
|
480
|
-
|
481
|
-
clock.tick(0);
|
482
|
-
|
483
|
-
expect(delayedFn1).toHaveBeenCalled();
|
484
|
-
expect(delayedFn2).not.toHaveBeenCalled();
|
485
|
-
expect(delayedFn3).not.toHaveBeenCalled();
|
486
|
-
|
487
|
-
clock.tick(50);
|
488
|
-
|
489
|
-
expect(recurring1).toHaveBeenCalled();
|
490
|
-
expect(recurring1.calls.count()).toBe(1);
|
491
|
-
expect(delayedFn2).not.toHaveBeenCalled();
|
492
|
-
expect(delayedFn3).not.toHaveBeenCalled();
|
493
|
-
|
494
|
-
clock.tick(50);
|
495
|
-
|
496
|
-
expect(recurring1.calls.count()).toBe(2);
|
497
|
-
expect(delayedFn2).toHaveBeenCalled();
|
498
|
-
expect(delayedFn3).not.toHaveBeenCalled();
|
499
|
-
|
500
|
-
clock.tick(100);
|
501
|
-
|
502
|
-
expect(recurring1.calls.count()).toBe(4);
|
503
|
-
expect(delayedFn3).toHaveBeenCalled();
|
504
|
-
|
505
|
-
clock.clearInterval(intervalId);
|
506
|
-
clock.tick(50);
|
507
|
-
|
508
|
-
expect(recurring1.calls.count()).toBe(4);
|
509
|
-
});
|
510
|
-
|
511
|
-
it("can clear a previously set timeout", function() {
|
512
|
-
var clearedFn = jasmine.createSpy('clearedFn'),
|
513
|
-
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
514
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
515
|
-
clock = new jasmineUnderTest.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate),
|
516
|
-
timeoutId;
|
517
|
-
|
518
|
-
clock.install();
|
519
|
-
|
520
|
-
timeoutId = clock.setTimeout(clearedFn, 100);
|
521
|
-
expect(clearedFn).not.toHaveBeenCalled();
|
522
|
-
|
523
|
-
clock.clearTimeout(timeoutId);
|
524
|
-
clock.tick(100);
|
525
|
-
|
526
|
-
expect(clearedFn).not.toHaveBeenCalled();
|
527
|
-
});
|
528
|
-
|
529
|
-
it("can clear a previously set interval using that interval's handler", function() {
|
530
|
-
var spy = jasmine.createSpy('spy'),
|
531
|
-
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
532
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
533
|
-
clock = new jasmineUnderTest.Clock({setInterval: function() {}}, function () { return delayedFunctionScheduler; }, mockDate),
|
534
|
-
intervalId;
|
535
|
-
|
536
|
-
clock.install();
|
537
|
-
|
538
|
-
intervalId = clock.setInterval(function() {
|
539
|
-
spy();
|
540
|
-
clock.clearInterval(intervalId);
|
541
|
-
}, 100);
|
542
|
-
clock.tick(200);
|
543
|
-
|
544
|
-
expect(spy.calls.count()).toEqual(1);
|
545
|
-
});
|
546
|
-
|
547
|
-
it("correctly schedules functions after the Clock has advanced", function() {
|
548
|
-
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
549
|
-
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
550
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
551
|
-
clock = new jasmineUnderTest.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
|
552
|
-
|
553
|
-
clock.install();
|
554
|
-
|
555
|
-
clock.tick(100);
|
556
|
-
clock.setTimeout(delayedFn1, 10, ['some', 'arg']);
|
557
|
-
clock.tick(5);
|
558
|
-
expect(delayedFn1).not.toHaveBeenCalled();
|
559
|
-
clock.tick(5);
|
560
|
-
expect(delayedFn1).toHaveBeenCalled();
|
561
|
-
});
|
562
|
-
|
563
|
-
it("correctly schedules functions while the Clock is advancing", function() {
|
564
|
-
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
565
|
-
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
566
|
-
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
567
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
568
|
-
clock = new jasmineUnderTest.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
|
569
|
-
|
570
|
-
delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 0); });
|
571
|
-
clock.install();
|
572
|
-
clock.setTimeout(delayedFn1, 5);
|
573
|
-
|
574
|
-
clock.tick(5);
|
575
|
-
expect(delayedFn1).toHaveBeenCalled();
|
576
|
-
expect(delayedFn2).not.toHaveBeenCalled();
|
577
|
-
|
578
|
-
clock.tick();
|
579
|
-
expect(delayedFn2).toHaveBeenCalled();
|
580
|
-
});
|
581
|
-
|
582
|
-
it("correctly calls functions scheduled while the Clock is advancing", function() {
|
583
|
-
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
584
|
-
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
585
|
-
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
586
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
587
|
-
clock = new jasmineUnderTest.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
|
588
|
-
|
589
|
-
delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 1); });
|
590
|
-
clock.install();
|
591
|
-
clock.setTimeout(delayedFn1, 5);
|
592
|
-
|
593
|
-
clock.tick(6);
|
594
|
-
expect(delayedFn1).toHaveBeenCalled();
|
595
|
-
expect(delayedFn2).toHaveBeenCalled();
|
596
|
-
});
|
597
|
-
|
598
|
-
it("correctly schedules functions scheduled while the Clock is advancing but after the Clock is uninstalled", function() {
|
599
|
-
var delayedFn1 = jasmine.createSpy('delayedFn1'),
|
600
|
-
delayedFn2 = jasmine.createSpy('delayedFn2'),
|
601
|
-
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
602
|
-
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
|
603
|
-
clock = new jasmineUnderTest.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
|
604
|
-
|
605
|
-
delayedFn1.and.callFake(function() {
|
606
|
-
clock.uninstall();
|
607
|
-
clock.install();
|
608
|
-
clock.setTimeout(delayedFn2, 0);
|
609
|
-
});
|
610
|
-
|
611
|
-
clock.install();
|
612
|
-
clock.setTimeout(delayedFn1, 1);
|
613
|
-
|
614
|
-
clock.tick(1);
|
615
|
-
expect(delayedFn1).toHaveBeenCalled();
|
616
|
-
expect(delayedFn2).not.toHaveBeenCalled();
|
617
|
-
|
618
|
-
clock.tick(1);
|
619
|
-
expect(delayedFn2).toHaveBeenCalled();
|
620
|
-
});
|
621
|
-
|
622
|
-
it("does not mock the Date object by default", function() {
|
623
|
-
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
624
|
-
global = {Date: Date},
|
625
|
-
mockDate = new jasmineUnderTest.MockDate(global),
|
626
|
-
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
|
627
|
-
|
628
|
-
clock.install();
|
629
|
-
|
630
|
-
expect(global.Date).toEqual(Date);
|
631
|
-
|
632
|
-
var now = new global.Date().getTime();
|
633
|
-
|
634
|
-
clock.tick(50);
|
635
|
-
|
636
|
-
expect(new global.Date().getTime() - now).not.toEqual(50);
|
637
|
-
});
|
638
|
-
|
639
|
-
it("mocks the Date object and sets it to current time", function() {
|
640
|
-
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
641
|
-
global = {Date: Date},
|
642
|
-
mockDate = new jasmineUnderTest.MockDate(global),
|
643
|
-
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
|
644
|
-
|
645
|
-
clock.install().mockDate();
|
646
|
-
|
647
|
-
var now = new global.Date().getTime();
|
648
|
-
|
649
|
-
clock.tick(50);
|
650
|
-
|
651
|
-
expect(new global.Date().getTime() - now).toEqual(50);
|
652
|
-
|
653
|
-
var timeoutDate = 0;
|
654
|
-
clock.setTimeout(function() {
|
655
|
-
timeoutDate = new global.Date().getTime();
|
656
|
-
}, 100);
|
657
|
-
|
658
|
-
clock.tick(100);
|
659
|
-
|
660
|
-
expect(timeoutDate - now).toEqual(150);
|
661
|
-
});
|
662
|
-
|
663
|
-
it("mocks the Date object and sets it to a given time", function() {
|
664
|
-
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
665
|
-
global = {Date: Date},
|
666
|
-
mockDate = new jasmineUnderTest.MockDate(global),
|
667
|
-
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate),
|
668
|
-
baseTime = new Date(2013, 9, 23);
|
669
|
-
|
670
|
-
|
671
|
-
clock.install().mockDate(baseTime);
|
672
|
-
|
673
|
-
var now = new global.Date().getTime();
|
674
|
-
|
675
|
-
expect(now).toEqual(baseTime.getTime());
|
676
|
-
|
677
|
-
clock.tick(50);
|
678
|
-
|
679
|
-
expect(new global.Date().getTime()).toEqual(baseTime.getTime() + 50);
|
680
|
-
|
681
|
-
var timeoutDate = 0;
|
682
|
-
clock.setTimeout(function() {
|
683
|
-
timeoutDate = new global.Date().getTime();
|
684
|
-
}, 100);
|
685
|
-
|
686
|
-
clock.tick(100);
|
687
|
-
|
688
|
-
expect(timeoutDate).toEqual(baseTime.getTime() + 150);
|
689
|
-
});
|
690
|
-
|
691
|
-
it("mocks the Date object and updates the date per delayed function", function () {
|
692
|
-
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
693
|
-
global = {Date: Date},
|
694
|
-
mockDate = new jasmineUnderTest.MockDate(global),
|
695
|
-
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate),
|
696
|
-
baseTime = new Date();
|
697
|
-
|
698
|
-
clock.install().mockDate(baseTime);
|
699
|
-
|
700
|
-
var actualTimes = [];
|
701
|
-
var pushCurrentTime = function() { actualTimes.push(global.Date().getTime()); };
|
702
|
-
delayedFunctionScheduler.scheduleFunction(pushCurrentTime);
|
703
|
-
delayedFunctionScheduler.scheduleFunction(pushCurrentTime, 1);
|
704
|
-
delayedFunctionScheduler.scheduleFunction(pushCurrentTime, 3);
|
705
|
-
|
706
|
-
clock.tick(1);
|
707
|
-
expect(global.Date().getTime()).toEqual(baseTime.getTime() + 1);
|
708
|
-
|
709
|
-
clock.tick(3);
|
710
|
-
expect(global.Date().getTime()).toEqual(baseTime.getTime() + 4);
|
711
|
-
|
712
|
-
clock.tick(1);
|
713
|
-
expect(global.Date().getTime()).toEqual(baseTime.getTime() + 5);
|
714
|
-
|
715
|
-
expect(actualTimes).toEqual([baseTime.getTime(), baseTime.getTime() + 1, baseTime.getTime() + 3]);
|
716
|
-
})
|
717
|
-
|
718
|
-
it('correctly clears a scheduled timeout while the Clock is advancing', function () {
|
719
|
-
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
720
|
-
global = {Date: Date, setTimeout: undefined},
|
721
|
-
mockDate = new jasmineUnderTest.MockDate(global),
|
722
|
-
clock = new jasmineUnderTest.Clock(global, function () { return delayedFunctionScheduler; }, mockDate);
|
723
|
-
|
724
|
-
clock.install();
|
725
|
-
|
726
|
-
var timerId2;
|
727
|
-
|
728
|
-
global.setTimeout(function () {
|
729
|
-
global.clearTimeout(timerId2);
|
730
|
-
}, 100);
|
731
|
-
|
732
|
-
timerId2 = global.setTimeout(fail, 100);
|
733
|
-
|
734
|
-
clock.tick(100);
|
735
|
-
});
|
736
|
-
|
737
|
-
it('correctly clears a scheduled interval while the Clock is advancing', function () {
|
738
|
-
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
|
739
|
-
global = {Date: Date, setTimeout: undefined},
|
740
|
-
mockDate = new jasmineUnderTest.MockDate(global),
|
741
|
-
clock = new jasmineUnderTest.Clock(global, function () { return delayedFunctionScheduler; }, mockDate);
|
742
|
-
|
743
|
-
clock.install();
|
744
|
-
|
745
|
-
var timerId2;
|
746
|
-
var timerId1 = global.setInterval(function () {
|
747
|
-
global.clearInterval(timerId2);
|
748
|
-
}, 100);
|
749
|
-
|
750
|
-
timerId2 = global.setInterval(fail, 100);
|
751
|
-
|
752
|
-
clock.tick(400);
|
753
|
-
});
|
754
|
-
});
|