···254254 ```ts
255255 // increment.test.js
256256 import { vi } from 'vitest'
257257-257257+258258 // axios is a default export from `__mocks__/axios.js`
259259 import axios from 'axios'
260260-260260+261261 // increment is a named export from `src/__mocks__/increment.js`
262262 import { increment } from '../increment.js'
263263···371371372372 ```ts
373373 import { vi } from 'vitest'
374374-374374+375375 import { data } from './data.js' // Will not get reevaluated beforeEach test
376376377377 beforeEach(() => {
···706706707707 The implementation is based internally on [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers).
708708709709+## vi.isFakeTimers
710710+711711+- **Type:** `() => boolean`
712712+- **Version:** Since Vitest 0.34.5
713713+714714+ Returns `true` if fake timers are enabled.
715715+709716## vi.useRealTimers
710717711718- **Type:** `() => Vitest`
712719713720 When timers are run out, you may call this method to return mocked timers to its original implementations. All timers that were run before will not be restored.
721721+722722+### vi.waitFor
723723+724724+- **Type:** `function waitFor<T>(callback: WaitForCallback<T>, options?: number | WaitForOptions): Promise<T>`
725725+- **Version**: Since Vitest 0.34.5
726726+727727+Wait for the callback to execute successfully. If the callback throws an error or returns a rejected promise it will continue to wait until it succeeds or times out.
728728+729729+This is very useful when you need to wait for some asynchronous action to complete, for example, when you start a server and need to wait for it to start.
730730+731731+```ts
732732+import { test, vi } from 'vitest'
733733+734734+test('Server started successfully', async () => {
735735+ let server = false
736736+737737+ setTimeout(() => {
738738+ server = true
739739+ }, 100)
740740+741741+ function checkServerStart() {
742742+ if (!server)
743743+ throw new Error('Server not started')
744744+745745+ console.log('Server started')
746746+ }
747747+748748+ const res = await vi.waitFor(checkServerStart, {
749749+ timeout: 500, // default is 1000
750750+ interval: 20, // default is 50
751751+ })
752752+ expect(server).toBe(true)
753753+})
754754+```
755755+756756+It also works for asynchronous callbacks
757757+758758+```ts
759759+import { test, vi } from 'vitest'
760760+761761+test('Server started successfully', async () => {
762762+ async function startServer() {
763763+ return new Promise((resolve) => {
764764+ setTimeout(() => {
765765+ server = true
766766+ resolve('Server started')
767767+ }, 100)
768768+ })
769769+ }
770770+771771+ const server = await vi.waitFor(startServer, {
772772+ timeout: 500, // default is 1000
773773+ interval: 20, // default is 50
774774+ })
775775+ expect(server).toBe('Server started')
776776+})
777777+```
778778+779779+If `vi.useFakeTimers` is used, `vi.waitFor` automatically calls `vi.advanceTimersByTime(interval)` in every check callback.