jestFakeTimers.d.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 { ModuleMocker } from 'jest-mock';
  9. import { StackTraceConfig } from 'jest-message-util';
  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 _cancelledImmediates;
  17. private _cancelledTicks;
  18. private _config;
  19. private _disposed?;
  20. private _fakeTimerAPIs;
  21. private _global;
  22. private _immediates;
  23. private _maxLoops;
  24. private _moduleMocker;
  25. private _now;
  26. private _ticks;
  27. private _timerAPIs;
  28. private _timers;
  29. private _uuidCounter;
  30. private _timerConfig;
  31. constructor({ global, moduleMocker, timerConfig, config, maxLoops, }: {
  32. global: NodeJS.Global;
  33. moduleMocker: ModuleMocker;
  34. timerConfig: TimerConfig<TimerRef>;
  35. config: StackTraceConfig;
  36. maxLoops?: number;
  37. });
  38. clearAllTimers(): void;
  39. dispose(): void;
  40. reset(): void;
  41. runAllTicks(): void;
  42. runAllImmediates(): void;
  43. private _runImmediate;
  44. runAllTimers(): void;
  45. runOnlyPendingTimers(): void;
  46. advanceTimersToNextTimer(steps?: number): void;
  47. advanceTimersByTime(msToRun: number): void;
  48. runWithRealTimers(cb: Callback): void;
  49. useRealTimers(): void;
  50. useFakeTimers(): void;
  51. getTimerCount(): number;
  52. private _checkFakeTimers;
  53. private _createMocks;
  54. private _fakeClearTimer;
  55. private _fakeClearImmediate;
  56. private _fakeNextTick;
  57. private _fakeSetImmediate;
  58. private _fakeSetInterval;
  59. private _fakeSetTimeout;
  60. private _getNextTimerHandle;
  61. private _runTimerHandle;
  62. }
  63. export {};
  64. //# sourceMappingURL=jestFakeTimers.d.ts.map