()
| 144 | } |
| 145 | |
| 146 | useFakeTimers(): void { |
| 147 | const fakeDate = this._fakingDate || Date.now() |
| 148 | if (this._fakingDate) { |
| 149 | resetDate() |
| 150 | this._fakingDate = null |
| 151 | } |
| 152 | |
| 153 | if (this._fakingTime) { |
| 154 | this._clock.uninstall() |
| 155 | } |
| 156 | |
| 157 | const toFake = Object.keys(this._fakeTimers.timers) |
| 158 | // Do not mock timers internally used by node by default. It can still be mocked through userConfig. |
| 159 | .filter( |
| 160 | timer => timer !== 'nextTick' && timer !== 'queueMicrotask', |
| 161 | ) as (keyof FakeTimerWithContext['timers'])[] |
| 162 | |
| 163 | if (this._userConfig?.toFake?.includes('nextTick') && isChildProcess()) { |
| 164 | throw new Error( |
| 165 | 'process.nextTick cannot be mocked inside child_process', |
| 166 | ) |
| 167 | } |
| 168 | |
| 169 | this._clock = this._fakeTimers.install({ |
| 170 | now: fakeDate, |
| 171 | ...this._userConfig, |
| 172 | toFake: this._userConfig?.toFake || toFake, |
| 173 | ignoreMissingTimers: true, |
| 174 | }) |
| 175 | |
| 176 | this._fakingTime = true |
| 177 | } |
| 178 | |
| 179 | reset(): void { |
| 180 | if (this._checkFakeTimers()) { |
no test coverage detected