| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -328,6 +328,7 @@ class MockTimers { | |||
| 328 | 328 | if (timer?.priorityQueuePosition !== undefined) { | |
| 329 | 329 | this.#executionQueue.removeAt(timer.priorityQueuePosition); | |
| 330 | 330 | timer.priorityQueuePosition = undefined; | |
| 331 | + timer.interval = undefined; | ||
| 331 | 332 | } | |
| 332 | 333 | } | |
| 333 | 334 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,6 +201,27 @@ describe('Mock Timers Test Suite', () => { | |||
| 201 | 201 | // Should not throw | |
| 202 | 202 | }); | |
| 203 | 203 | }); | |
| 204 | + | ||
| 205 | + it('interval cleared inside callback should only fire once', (t) => { | ||
| 206 | + t.mock.timers.enable(); | ||
| 207 | + const calls = []; | ||
| 208 | + | ||
| 209 | + setInterval(() => { | ||
| 210 | + calls.push('foo'); | ||
| 211 | + }, 10); | ||
| 212 | + const timerId = setInterval(() => { | ||
| 213 | + calls.push('bar'); | ||
| 214 | + clearInterval(timerId); | ||
| 215 | + }, 10); | ||
| 216 | + | ||
| 217 | + t.mock.timers.tick(10); | ||
| 218 | + t.mock.timers.tick(10); | ||
| 219 | + | ||
| 220 | + assert.deepStrictEqual( | ||
| 221 | + calls, | ||
| 222 | + ['foo', 'bar', 'foo'], | ||
| 223 | + ); | ||
| 224 | + }); | ||
| 204 | 225 | }); | |
| 205 | 226 | ||
| 206 | 227 | describe('globals/timers', () => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments