legacyFakeTimers.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. /// <reference types="node" />
  8. import { StackTraceConfig } from 'jest-message-util';
  9. import type { ModuleMocker } from 'jest-mock';
  10. declare type Callback = (...args: Array<unknown>) => void;
  11. declare type TimerConfig<Ref> = {
  12. idToRef: (id: number) => Ref;
  13. refToId: (ref: Ref) => number | void;
  14. };
  15. export default class FakeTimers<TimerRef> {
  16. private _cancelledTicks;
  17. private _config;
  18. private _disposed?;
  19. private _fakeTimerAPIs;
  20. private _global;
  21. private _immediates;
  22. private _maxLoops;
  23. private _moduleMocker;
  24. private _now;
  25. private _ticks;
  26. private _timerAPIs;
  27. private _timers;
  28. private _uuidCounter;
  29. private _timerConfig;
  30. constructor({ global, moduleMocker, timerConfig, config, maxLoops, }: {
  31. global: NodeJS.Global;
  32. moduleMocker: ModuleMocker;
  33. timerConfig: TimerConfig<TimerRef>;
  34. config: StackTraceConfig;
  35. maxLoops?: number;
  36. });
  37. clearAllTimers(): void;
  38. dispose(): void;
  39. reset(): void;
  40. runAllTicks(): void;
  41. runAllImmediates(): void;
  42. private _runImmediate;
  43. runAllTimers(): void;
  44. runOnlyPendingTimers(): void;
  45. advanceTimersToNextTimer(steps?: number): void;
  46. advanceTimersByTime(msToRun: number): void;
  47. runWithRealTimers(cb: Callback): void;
  48. useRealTimers(): void;
  49. useFakeTimers(): void;
  50. getTimerCount(): number;
  51. private _checkFakeTimers;
  52. private _createMocks;
  53. private _fakeClearTimer;
  54. private _fakeClearImmediate;
  55. private _fakeNextTick;
  56. private _fakeSetImmediate;
  57. private _fakeSetInterval;
  58. private _fakeSetTimeout;
  59. private _getNextTimerHandle;
  60. private _runTimerHandle;
  61. }
  62. export {};