|
18 | 18 | * Use of this source code is governed by an MIT-style license that can be |
19 | 19 | * found in the LICENSE file at https://angular.io/license |
20 | 20 | */ |
| 21 | +var __read = (undefined && undefined.__read) || function (o, n) { |
| 22 | + var m = typeof Symbol === "function" && o[Symbol.iterator]; |
| 23 | + if (!m) return o; |
| 24 | + var i = m.call(o), r, ar = [], e; |
| 25 | + try { |
| 26 | + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); |
| 27 | + } |
| 28 | + catch (error) { e = { error: error }; } |
| 29 | + finally { |
| 30 | + try { |
| 31 | + if (r && !r.done && (m = i["return"])) m.call(i); |
| 32 | + } |
| 33 | + finally { if (e) throw e.error; } |
| 34 | + } |
| 35 | + return ar; |
| 36 | +}; |
| 37 | +var __spread = (undefined && undefined.__spread) || function () { |
| 38 | + for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); |
| 39 | + return ar; |
| 40 | +}; |
21 | 41 | (function (global) { |
22 | 42 | var OriginalDate = global.Date; |
23 | 43 | var FakeDate = /** @class */ (function () { |
24 | 44 | function FakeDate() { |
25 | | - var d = new OriginalDate(); |
26 | | - d.setTime(global.Date.now()); |
27 | | - return d; |
| 45 | + if (arguments.length === 0) { |
| 46 | + var d = new OriginalDate(); |
| 47 | + d.setTime(FakeDate.now()); |
| 48 | + return d; |
| 49 | + } |
| 50 | + else { |
| 51 | + var args = Array.prototype.slice.call(arguments); |
| 52 | + return new (OriginalDate.bind.apply(OriginalDate, __spread([void 0], args)))(); |
| 53 | + } |
28 | 54 | } |
29 | | - FakeDate.UTC = function () { |
30 | | - return OriginalDate.UTC(); |
31 | | - }; |
32 | 55 | FakeDate.now = function () { |
33 | 56 | var fakeAsyncTestZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec'); |
34 | 57 | if (fakeAsyncTestZoneSpec) { |
35 | 58 | return fakeAsyncTestZoneSpec.getCurrentRealTime() + fakeAsyncTestZoneSpec.getCurrentTime(); |
36 | 59 | } |
37 | 60 | return OriginalDate.now.apply(this, arguments); |
38 | 61 | }; |
39 | | - FakeDate.parse = function () { |
40 | | - return OriginalDate.parse(); |
41 | | - }; |
42 | 62 | return FakeDate; |
43 | 63 | }()); |
| 64 | + FakeDate.UTC = OriginalDate.UTC; |
| 65 | + FakeDate.parse = OriginalDate.parse; |
| 66 | + // keep a reference for zone patched timer function |
| 67 | + var timers = { |
| 68 | + setTimeout: global.setTimeout, |
| 69 | + setInterval: global.setInterval, |
| 70 | + clearTimeout: global.clearTimeout, |
| 71 | + clearInterval: global.clearInterval |
| 72 | + }; |
44 | 73 | var Scheduler = /** @class */ (function () { |
45 | 74 | function Scheduler() { |
46 | 75 | // Next scheduler id. |
|
50 | 79 | // Current simulated time in millis. |
51 | 80 | this._currentTime = 0; |
52 | 81 | // Current real time in millis. |
53 | | - this._currentRealTime = Date.now(); |
| 82 | + this._currentRealTime = OriginalDate.now(); |
54 | 83 | } |
55 | 84 | Scheduler.prototype.getCurrentTime = function () { |
56 | 85 | return this._currentTime; |
|
309 | 338 | } |
310 | 339 | global['Date'] = FakeDate; |
311 | 340 | FakeDate.prototype = OriginalDate.prototype; |
| 341 | + // try check and reset timers |
| 342 | + // because jasmine.clock().install() may |
| 343 | + // have replaced the global timer |
| 344 | + FakeAsyncTestZoneSpec.checkTimerPatch(); |
312 | 345 | }; |
313 | 346 | FakeAsyncTestZoneSpec.resetDate = function () { |
314 | 347 | if (global['Date'] === FakeDate) { |
315 | 348 | global['Date'] = OriginalDate; |
316 | 349 | } |
317 | 350 | }; |
| 351 | + FakeAsyncTestZoneSpec.checkTimerPatch = function () { |
| 352 | + if (global.setTimeout !== timers.setTimeout) { |
| 353 | + global.setTimeout = timers.setTimeout; |
| 354 | + global.clearTimeout = timers.clearTimeout; |
| 355 | + } |
| 356 | + if (global.setInterval !== timers.setInterval) { |
| 357 | + global.setInterval = timers.setInterval; |
| 358 | + global.clearInterval = timers.clearInterval; |
| 359 | + } |
| 360 | + }; |
318 | 361 | FakeAsyncTestZoneSpec.prototype.lockDatePatch = function () { |
319 | 362 | this.patchDateLocked = true; |
320 | 363 | FakeAsyncTestZoneSpec.patchDate(); |
|
0 commit comments