Repository: facebook/jest
File: packages/jest-types/__typetests__/jest.test.ts (TypeScript)

Code before:
);
expectError(jest.useFakeTimers({doNotFake: ['globalThis']}));

expectType<typeof jest>(jest.useFakeTimers({legacyFakeTimers: true}));
expectError(jest.useFakeTimers({legacyFakeTimers: 1000}));
expectError(jest.useFakeTimers({doNotFake: ['Date'], legacyFakeTimers: true}));
expectError(jest.useFakeTimers({enableGlobally: true, legacyFakeTimers: true}));
expectError(jest.useFakeTimers({legacyFakeTimers: true, now: 1483228800000}));
expectError(jest.useFakeTimers({legacyFakeTimers: true, timerLimit: 1000}));

expectType<typeof jest>(jest.useFakeTimers({now: 1483228800000}));
expectType<typeof jest>(jest.useFakeTimers({now: Date.now()}));
expectType<typeof jest>(jest.useFakeTimers({now: new Date(1995, 11, 17)}));
expectError(jest.useFakeTimers({now: '1995-12-17T03:24:00'}));

expectType<typeof jest>(jest.useFakeTimers({timerLimit: 1000}));
expectError(jest.useFakeTimers({timerLimit: true}));

expectError(jest.useFakeTimers({enableGlobally: true}));
expectError(jest.useFakeTimers('legacy'));
expectError(jest.useFakeTimers('modern'));

expectType<typeof jest>(jest.useRealTimers());
expectError(jest.useRealTimers(true));

expectType<Promise<number>>(jest.advanceTimersByTimeAsync(250));
expectError(jest.advanceTimersByTimeAsync());

expectType<Promise<number>>(jest.advanceTimersToNextTimerAsync());
expectError(jest.advanceTimersToNextTimerAsync('jest'));

expectType<Promise<number>>(jest.runAllTimersAsync());
expectError(jest.runAllTimersAsync('jest'));

expectType<Promise<number>>(jest.runOnlyPendingTimersAsync());
expectError(jest.runOnlyPendingTimersAsync('jest'));

// Misc

expectType<typeof jest>(jest.retryTimes(3));
expectType<typeof jest>(jest.retryTimes(3, {logErrorsBeforeRetry: true}));
expectError(jest.retryTimes(3, {logErrorsBeforeRetry: 'all'}));
expectError(jest.retryTimes({logErrorsBeforeRetry: true}));
expectError(jest.retryTimes());

expectType<typeof jest>(jest.setTimeout(6000));
expectError(jest.setTimeout());

expectType<number>(jest.getSeed());
expectError(jest.getSeed(123));


Review comment (suggestion):
Good to see these (; Could you keep alphabetical order? I mean, `advanceTimersByTimeAsync` should be placed after `advanceTimersByTime`, `advanceTimersToNextTimerAsync` after `advanceTimersToNextTimer` and so on.

Code after:
      'queueMicrotask',
      'requestAnimationFrame',
      'cancelAnimationFrame',
      'requestIdleCallback',
      'cancelIdleCallback',
      'setImmediate',
      'clearImmediate',
      'setInterval',
      'clearInterval',
      'setTimeout',
      'clearTimeout',
    ],
  }),
);
expectError(jest.useFakeTimers({doNotFake: ['globalThis']}));

expectType<typeof jest>(jest.useFakeTimers({legacyFakeTimers: true}));
expectError(jest.useFakeTimers({legacyFakeTimers: 1000}));
expectError(jest.useFakeTimers({doNotFake: ['Date'], legacyFakeTimers: true}));
expectError(jest.useFakeTimers({enableGlobally: true, legacyFakeTimers: true}));
expectError(jest.useFakeTimers({legacyFakeTimers: true, now: 1483228800000}));
expectError(jest.useFakeTimers({legacyFakeTimers: true, timerLimit: 1000}));

expectType<typeof jest>(jest.useFakeTimers({now: 1483228800000}));
expectType<typeof jest>(jest.useFakeTimers({now: Date.now()}));
expectType<typeof jest>(jest.useFakeTimers({now: new Date(1995, 11, 17)}));
expectError(jest.useFakeTimers({now: '1995-12-17T03:24:00'}));

expectType<typeof jest>(jest.useFakeTimers({timerLimit: 1000}));
expectError(jest.useFakeTimers({timerLimit: true}));

expectError(jest.useFakeTimers({enableGlobally: true}));
expectError(jest.useFakeTimers('legacy'));
expectError(jest.useFakeTimers('modern'));

expectType<typeof jest>(jest.useRealTimers());
expectError(jest.useRealTimers(true));

// Misc

expectType<typeof jest>(jest.retryTimes(3));
expectType<typeof jest>(jest.retryTimes(3, {logErrorsBeforeRetry: true}));
expectError(jest.retryTimes(3, {logErrorsBeforeRetry: 'all'}));
expectError(jest.retryTimes({logErrorsBeforeRetry: true}));
expectError(jest.retryTimes());

expectType<typeof jest>(jest.setTimeout(6000));
expectError(jest.setTimeout());

expectType<number>(jest.getSeed());
expectError(jest.getSeed(123));