import { TaskPopulated, File, TaskResultPack, CancelReason } from '@vitest/runner'; export { Custom, DoneCallback, ExtendedContext, File, HookCleanupCallback, HookListener, OnTestFailedHandler, RunMode, RuntimeContext, SequenceHooks, SequenceSetupFiles, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, TaskBase, TaskContext, TaskCustomOptions, TaskMeta, TaskResult, TaskResultPack, TaskState, Test, TestAPI, TestContext, TestFunction, TestOptions, afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner'; export { b as bench } from './suite-ghspeorC.js'; import { ExpectStatic } from '@vitest/expect'; export { Assertion, AsymmetricMatchersContaining, ExpectStatic, JestAssertion } from '@vitest/expect'; import { F as FakeTimerInstallOpts, M as MockFactoryWithHelper, r as RuntimeConfig, P as ProvidedContext, A as AfterSuiteRunMeta, t as UserConsoleLog, R as ResolvedConfig, u as ModuleGraphData, v as Reporter } from './reporters-1evA5lom.js'; export { Q as ApiConfig, a9 as ArgumentsType, a8 as Arrayable, a6 as Awaitable, B as BaseCoverageOptions, ao as BenchFunction, am as Benchmark, ap as BenchmarkAPI, an as BenchmarkResult, al as BenchmarkUserOptions, L as BuiltinEnvironment, O as CSSModuleScopeStrategy, y as CollectLineNumbers, z as CollectLines, ab as Constructable, G as Context, o as ContextRPC, a2 as ContextTestEnvironment, ai as CoverageIstanbulOptions, C as CoverageOptions, b as CoverageProvider, c as CoverageProviderModule, ah as CoverageReporter, aj as CoverageV8Options, ak as CustomProviderOptions, X as DepsOptimizationOptions, E as Environment, S as EnvironmentOptions, ad as EnvironmentReturn, K as HappyDOMOptions, Z as InlineConfig, J as JSDOMOptions, ac as ModuleCache, aa as MutableArray, a7 as Nullable, af as OnServerRestartHandler, H as Pool, I as PoolOptions, $ as ProjectConfig, w as RawErrsMap, ag as ReportContext, a4 as ResolveIdFunction, a as ResolvedCoverageOptions, a3 as ResolvedTestEnvironment, D as RootAndTarget, a1 as RunnerRPC, f as RuntimeRPC, Y as TransformModePatterns, x as TscErrorInfo, _ as TypecheckConfig, U as UserConfig, a0 as UserWorkspaceConfig, e as Vitest, N as VitestEnvironment, V as VitestRunMode, ae as VmEnvironmentReturn, q as WorkerContext, p as WorkerGlobalState, a5 as WorkerRPC } from './reporters-1evA5lom.js'; import { spyOn, fn, MaybeMockedDeep, MaybeMocked, MaybePartiallyMocked, MaybePartiallyMockedDeep, MockInstance } from '@vitest/spy'; export { Mock, MockContext, MockInstance, Mocked, MockedClass, MockedFunction, MockedObject, SpyInstance } from '@vitest/spy'; export { SnapshotEnvironment } from '@vitest/snapshot/environment'; import { SnapshotResult } from '@vitest/snapshot'; export { SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, UncheckedSnapshot } from '@vitest/snapshot'; export { DiffOptions } from '@vitest/utils/diff'; import { TransformResult } from 'vite'; import * as chai from 'chai'; export { chai }; export { assert, should } from 'chai'; export { ErrorWithDiff, ParsedStack } from '@vitest/utils'; export { Bench as BenchFactory, Options as BenchOptions, Task as BenchTask, TaskResult as BenchTaskResult } from 'tinybench'; import '@vitest/runner/utils'; import 'vite-node'; import 'vite-node/client'; import '@vitest/snapshot/manager'; import 'vite-node/server'; import 'node:worker_threads'; import 'node:fs'; declare type Not = T extends true ? false : true; declare type And = Types[number] extends true ? true : false; declare type Eq = Left extends true ? Right : Not; declare const secret: unique symbol; declare type Secret = typeof secret; declare type IsNever = [T] extends [never] ? true : false; declare type IsAny = [T] extends [Secret] ? Not> : false; declare type IsUnknown = [unknown] extends [T] ? Not> : false; declare type PrintType = IsUnknown extends true ? 'unknown' : IsNever extends true ? 'never' : IsAny extends true ? never : boolean extends T ? 'boolean' : T extends boolean ? `literal boolean: ${T}` : string extends T ? 'string' : T extends string ? `literal string: ${T}` : number extends T ? 'number' : T extends number ? `literal number: ${T}` : T extends null ? 'null' : T extends undefined ? 'undefined' : T extends (...args: any[]) => any ? 'function' : '...'; /** Subjective "useful" keys from a type. For objects it's just `keyof` but for tuples/arrays it's the number keys * @example * UsefulKeys<{a: 1; b: 2}> // 'a' | 'b' * UsefulKeys<['a', 'b']> // '0' | '1' * UsefulKeys // number */ declare type UsefulKeys = T extends any[] ? { [K in keyof T]: K; }[number] : keyof T; declare type MismatchInfo = And<[Extends, '...'>, Not>]> extends true ? And<[Extends, Extends]> extends true ? Array[number], Extract[number]>> : { [K in UsefulKeys | UsefulKeys]: MismatchInfo; } : StrictEqualUsingBranding extends true ? Actual : `Expected: ${PrintType}, Actual: ${PrintType>}`; /** * Recursively walk a type and replace it with a branded type related to the original. This is useful for * equality-checking stricter than `A extends B ? B extends A ? true : false : false`, because it detects * the difference between a few edge-case types that vanilla typescript doesn't by default: * - `any` vs `unknown` * - `{ readonly a: string }` vs `{ a: string }` * - `{ a?: string }` vs `{ a: string | undefined }` * * Note: not very performant for complex types - this should only be used when you know you need it. If doing * an equality check, it's almost always better to use `StrictEqualUsingTSInternalIdenticalToOperator`. */ declare type DeepBrand = IsNever extends true ? { type: 'never'; } : IsAny extends true ? { type: 'any'; } : IsUnknown extends true ? { type: 'unknown'; } : T extends string | number | boolean | symbol | bigint | null | undefined | void ? { type: 'primitive'; value: T; } : T extends new (...args: any[]) => any ? { type: 'constructor'; params: ConstructorParams; instance: DeepBrand any>>>; } : T extends (...args: infer P) => infer R ? { type: 'function'; params: DeepBrand

; return: DeepBrand; this: DeepBrand>; props: DeepBrand>; } : T extends any[] ? { type: 'array'; items: { [K in keyof T]: T[K]; }; } : { type: 'object'; properties: { [K in keyof T]: DeepBrand; }; readonly: ReadonlyKeys; required: RequiredKeys; optional: OptionalKeys; constructorParams: DeepBrand>; }; declare type RequiredKeys = Extract<{ [K in keyof T]-?: {} extends Pick ? never : K; }[keyof T], keyof T>; declare type OptionalKeys = Exclude>; declare type ReadonlyKeys = Extract<{ [K in keyof T]-?: ReadonlyEquivalent<{ [_K in K]: T[K]; }, { -readonly [_K in K]: T[K]; }> extends true ? never : K; }[keyof T], keyof T>; declare type ReadonlyEquivalent = Extends<(() => T extends X ? true : false), (() => T extends Y ? true : false)>; /** Returns true if `L extends R`. Explicitly checks for `never` since that can give unexpected results. */ declare type Extends = IsNever extends true ? IsNever : [L] extends [R] ? true : false; declare type ExtendsUsingBranding = Extends, DeepBrand>; declare type ExtendsExcludingAnyOrNever = IsAny extends true ? IsAny : Extends; declare type StrictEqualUsingTSInternalIdenticalToOperator = (() => T extends (L & T) | T ? true : false) extends () => T extends (R & T) | T ? true : false ? IsNever extends IsNever ? true : false : false; declare type StrictEqualUsingBranding = And<[ ExtendsUsingBranding, ExtendsUsingBranding ]>; declare type Params = Actual extends (...args: infer P) => any ? P : never; declare type ConstructorParams = Actual extends new (...args: infer P) => any ? Actual extends new () => any ? P | [] : P : never; declare const mismatch: unique symbol; declare type Mismatch = { [mismatch]: 'mismatch'; }; /** A type which should match anything passed as a value but *doesn't* match `Mismatch` - helps TypeScript select the right overload for `toEqualTypeOf` and `toMatchTypeOf`. */ declare const avalue: unique symbol; declare type AValue = { [avalue]?: undefined; } | string | number | boolean | symbol | bigint | null | undefined | void; declare type MismatchArgs = Eq extends true ? [] : [Mismatch]; declare const inverted: unique symbol; declare type Inverted = { [inverted]: T; }; declare const expectNull: unique symbol; declare type ExpectNull = { [expectNull]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectUndefined: unique symbol; declare type ExpectUndefined = { [expectUndefined]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectNumber: unique symbol; declare type ExpectNumber = { [expectNumber]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectString: unique symbol; declare type ExpectString = { [expectString]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectBoolean: unique symbol; declare type ExpectBoolean = { [expectBoolean]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectVoid: unique symbol; declare type ExpectVoid = { [expectVoid]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectFunction: unique symbol; declare type ExpectFunction = { [expectFunction]: T; result: ExtendsExcludingAnyOrNever any>; }; declare const expectObject: unique symbol; declare type ExpectObject = { [expectObject]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectArray: unique symbol; declare type ExpectArray = { [expectArray]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectSymbol: unique symbol; declare type ExpectSymbol = { [expectSymbol]: T; result: ExtendsExcludingAnyOrNever; }; declare const expectAny: unique symbol; declare type ExpectAny = { [expectAny]: T; result: IsAny; }; declare const expectUnknown: unique symbol; declare type ExpectUnknown = { [expectUnknown]: T; result: IsUnknown; }; declare const expectNever: unique symbol; declare type ExpectNever = { [expectNever]: T; result: IsNever; }; declare const expectNullable: unique symbol; declare type ExpectNullable = { [expectNullable]: T; result: Not>>; }; declare type Scolder = Expecter['result'] extends Options['positive'] ? () => true : Options['positive'] extends true ? Expecter : Inverted; interface PositiveExpectTypeOf extends BaseExpectTypeOf { toEqualTypeOf: { extends true ? unknown : MismatchInfo>(value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`. ...MISMATCH: MismatchArgs, true>): true; extends true ? unknown : MismatchInfo>(...MISMATCH: MismatchArgs, true>): true; }; toMatchTypeOf: { extends true ? unknown : MismatchInfo>(value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`. ...MISMATCH: MismatchArgs, true>): true; extends true ? unknown : MismatchInfo>(...MISMATCH: MismatchArgs, true>): true; }; toHaveProperty: (key: K, ...MISMATCH: MismatchArgs, true>) => K extends keyof Actual ? PositiveExpectTypeOf : true; not: NegativeExpectTypeOf; branded: { toEqualTypeOf: extends true ? unknown : MismatchInfo>(...MISMATCH: MismatchArgs, true>) => true; }; } interface NegativeExpectTypeOf extends BaseExpectTypeOf { toEqualTypeOf: { (value: Expected & AValue, ...MISMATCH: MismatchArgs, false>): true; (...MISMATCH: MismatchArgs, false>): true; }; toMatchTypeOf: { (value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`. ...MISMATCH: MismatchArgs, false>): true; (...MISMATCH: MismatchArgs, false>): true; }; toHaveProperty: (key: K, ...MISMATCH: MismatchArgs, false>) => true; } declare type ExpectTypeOf = Options['positive'] extends true ? PositiveExpectTypeOf : NegativeExpectTypeOf; interface BaseExpectTypeOf { toBeAny: Scolder, Options>; toBeUnknown: Scolder, Options>; toBeNever: Scolder, Options>; toBeFunction: Scolder, Options>; toBeObject: Scolder, Options>; toBeArray: Scolder, Options>; toBeNumber: Scolder, Options>; toBeString: Scolder, Options>; toBeBoolean: Scolder, Options>; toBeVoid: Scolder, Options>; toBeSymbol: Scolder, Options>; toBeNull: Scolder, Options>; toBeUndefined: Scolder, Options>; toBeNullable: Scolder, Options>; toBeCallableWith: Options['positive'] extends true ? (...args: Params) => true : never; toBeConstructibleWith: Options['positive'] extends true ? (...args: ConstructorParams) => true : never; extract: (v?: V) => ExpectTypeOf, Options>; exclude: (v?: V) => ExpectTypeOf, Options>; parameter: >(number: K) => ExpectTypeOf[K], Options>; parameters: ExpectTypeOf, Options>; constructorParameters: ExpectTypeOf, Options>; thisParameter: ExpectTypeOf, Options>; instance: Actual extends new (...args: any[]) => infer I ? ExpectTypeOf : never; returns: Actual extends (...args: any[]) => infer R ? ExpectTypeOf : never; resolves: Actual extends PromiseLike ? ExpectTypeOf : never; items: Actual extends ArrayLike ? ExpectTypeOf : never; guards: Actual extends (v: any, ...args: any[]) => v is infer T ? ExpectTypeOf : never; asserts: Actual extends (v: any, ...args: any[]) => asserts v is infer T ? unknown extends T ? never : ExpectTypeOf : never; } declare type _ExpectTypeOf = { (actual: Actual): ExpectTypeOf; (): ExpectTypeOf; }; /** * Similar to Jest's `expect`, but with type-awareness. * Gives you access to a number of type-matchers that let you make assertions about the * form of a reference or generic type parameter. * * @example * import {foo, bar} from '../foo' * import {expectTypeOf} from 'expect-type' * * test('foo types', () => { * // make sure `foo` has type {a: number} * expectTypeOf(foo).toMatchTypeOf({a: 1}) * expectTypeOf(foo).toHaveProperty('a').toBeNumber() * * // make sure `bar` is a function taking a string: * expectTypeOf(bar).parameter(0).toBeString() * expectTypeOf(bar).returns.not.toBeAny() * }) * * @description * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples. */ declare const expectTypeOf: _ExpectTypeOf; interface AssertType { (value: T): void; } declare const assertType: AssertType; /** * This utils allows computational intensive tasks to only be ran once * across test reruns to improve the watch mode performance. * * Currently only works with `poolOptions..isolate: false` * * @experimental */ declare function runOnce(fn: (() => T), key?: string): T; /** * Get a boolean indicates whether the task is running in the first time. * Could only be `false` in watch mode. * * Currently only works with `isolate: false` * * @experimental */ declare function isFirstRun(): boolean; declare function createExpect(test?: TaskPopulated): ExpectStatic; declare const globalExpect: ExpectStatic; type WaitForCallback = () => T | Promise; interface WaitForOptions { /** * @description Time in ms between each check callback * @default 50ms */ interval?: number; /** * @description Time in ms after which the throw a timeout error * @default 1000ms */ timeout?: number; } declare function waitFor(callback: WaitForCallback, options?: number | WaitForOptions): Promise; type WaitUntilCallback = () => T | Promise; interface WaitUntilOptions extends Pick { } type Truthy = T extends false | '' | 0 | null | undefined ? never : T; declare function waitUntil(callback: WaitUntilCallback, options?: number | WaitUntilOptions): Promise>; type ESModuleExports = Record; interface VitestUtils { /** * Checks if fake timers are enabled. */ isFakeTimers(): boolean; /** * This method wraps all further calls to timers until [`vi.useRealTimers()`](https://vitest.dev/api/vi#vi-userealtimers) is called. */ useFakeTimers(config?: FakeTimerInstallOpts): VitestUtils; /** * Restores mocked timers to their original implementations. All timers that were scheduled before will be discarded. */ useRealTimers(): VitestUtils; /** * This method will call every timer that was initiated after [`vi.useFakeTimers`](https://vitest.dev/api/vi#vi-usefaketimers) call. * It will not fire any timer that was initiated during its call. */ runOnlyPendingTimers(): VitestUtils; /** * This method will asynchronously call every timer that was initiated after [`vi.useFakeTimers`](https://vitest.dev/api/vi#vi-usefaketimers) call, even asynchronous ones. * It will not fire any timer that was initiated during its call. */ runOnlyPendingTimersAsync(): Promise; /** * This method will invoke every initiated timer until the timer queue is empty. It means that every timer called during `runAllTimers` will be fired. * If you have an infinite interval, it will throw after 10,000 tries (can be configured with [`fakeTimers.loopLimit`](https://vitest.dev/config/#faketimers-looplimit)). */ runAllTimers(): VitestUtils; /** * This method will asynchronously invoke every initiated timer until the timer queue is empty. It means that every timer called during `runAllTimersAsync` will be fired even asynchronous timers. * If you have an infinite interval, it will throw after 10 000 tries (can be configured with [`fakeTimers.loopLimit`](https://vitest.dev/config/#faketimers-looplimit)). */ runAllTimersAsync(): Promise; /** * Calls every microtask that was queued by `process.nextTick`. This will also run all microtasks scheduled by themselves. */ runAllTicks(): VitestUtils; /** * This method will invoke every initiated timer until the specified number of milliseconds is passed or the queue is empty - whatever comes first. */ advanceTimersByTime(ms: number): VitestUtils; /** * This method will invoke every initiated timer until the specified number of milliseconds is passed or the queue is empty - whatever comes first. This will include and await asynchronously set timers. */ advanceTimersByTimeAsync(ms: number): Promise; /** * Will call next available timer. Useful to make assertions between each timer call. You can chain call it to manage timers by yourself. */ advanceTimersToNextTimer(): VitestUtils; /** * Will call next available timer and wait until it's resolved if it was set asynchronously. Useful to make assertions between each timer call. */ advanceTimersToNextTimerAsync(): Promise; /** * Get the number of waiting timers. */ getTimerCount(): number; /** * If fake timers are enabled, this method simulates a user changing the system clock (will affect date related API like `hrtime`, `performance.now` or `new Date()`) - however, it will not fire any timers. * If fake timers are not enabled, this method will only mock `Date.*` and `new Date()` calls. */ setSystemTime(time: number | string | Date): VitestUtils; /** * Returns mocked current date that was set using `setSystemTime`. If date is not mocked the method will return `null`. */ getMockedSystemTime(): Date | null; /** * When using `vi.useFakeTimers`, `Date.now` calls are mocked. If you need to get real time in milliseconds, you can call this function. */ getRealSystemTime(): number; /** * Removes all timers that are scheduled to run. These timers will never run in the future. */ clearAllTimers(): VitestUtils; /** * Creates a spy on a method or getter/setter of an object similar to [`vi.fn()`](https://vitest.dev/api/vi#vi-fn). It returns a [mock function](https://vitest.dev/api/mock). * * @example * const cart = { * getApples: () => 42 * } * * const spy = vi.spyOn(cart, 'getApples').mockReturnValue(10) * * expect(cart.getApples()).toBe(10) * expect(spy).toHaveBeenCalled() * expect(spy).toHaveReturnedWith(10) */ spyOn: typeof spyOn; /** * Creates a spy on a function, though can be initiated without one. Every time a function is invoked, it stores its call arguments, returns, and instances. Also, you can manipulate its behavior with [methods](https://vitest.dev/api/mock). * * If no function is given, mock will return `undefined`, when invoked. * * @example * const getApples = vi.fn(() => 0) * * getApples() * * expect(getApples).toHaveBeenCalled() * expect(getApples).toHaveReturnedWith(0) * * getApples.mockReturnValueOnce(5) * * expect(getApples()).toBe(5) * expect(getApples).toHaveNthReturnedWith(2, 5) */ fn: typeof fn; /** * 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. * * 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. * * @example * const server = createServer() * * await vi.waitFor( * () => { * if (!server.isReady) * throw new Error('Server not started') * * console.log('Server started') * }, { * timeout: 500, // default is 1000 * interval: 20, // default is 50 * } * ) */ waitFor: typeof waitFor; /** * This is similar to [`vi.waitFor`](https://vitest.dev/api/vi#vi-waitfor), but if the callback throws any errors, execution is immediately interrupted and an error message is received. * * If the callback returns a falsy value, the next check will continue until a truthy value is returned. This is useful when you need to wait for something to exist before taking the next step. * * @example * const element = await vi.waitUntil( * () => document.querySelector('.element'), * { * timeout: 500, // default is 1000 * interval: 20, // default is 50 * } * ) * * // do something with the element * expect(element.querySelector('.element-child')).toBeTruthy() */ waitUntil: typeof waitUntil; /** * Run the factory before imports are evaluated. You can return a value from the factory * to reuse it inside your [`vi.mock`](https://vitest.dev/api/vi#vi-mock) factory and tests. * * If used with [`vi.mock`](https://vitest.dev/api/vi#vi-mock), both will be hoisted in the order they are defined in. */ hoisted(factory: () => T): T; /** * Mocks every import call to the module even if it was already statically imported. * * The call to `vi.mock` is hoisted to the top of the file, so you don't have access to variables declared in the global file scope * unless they are defined with [`vi.hoisted`](https://vitest.dev/api/vi#vi-hoisted) before this call. * * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules). * @param path Path to the module. Can be aliased, if your Vitest config supports it * @param factory Mocked module factory. The result of this function will be an exports object */ mock(path: string, factory?: MockFactoryWithHelper): void; /** * Removes module from mocked registry. All calls to import will return the original module even if it was mocked before. * * This call is hoisted to the top of the file, so it will only unmock modules that were defined in `setupFiles`, for example. * @param path Path to the module. Can be aliased, if your Vitest config supports it */ unmock(path: string): void; /** * Mocks every subsequent [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) call. * * Unlike [`vi.mock`](https://vitest.dev/api/vi#vi-mock), this method will not mock statically imported modules because it is not hoisted to the top of the file. * * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules). * @param path Path to the module. Can be aliased, if your Vitest config supports it * @param factory Mocked module factory. The result of this function will be an exports object */ doMock(path: string, factory?: MockFactoryWithHelper): void; /** * Removes module from mocked registry. All subsequent calls to import will return original module. * * Unlike [`vi.unmock`](https://vitest.dev/api/vi#vi-unmock), this method is not hoisted to the top of the file. * @param path Path to the module. Can be aliased, if your Vitest config supports it */ doUnmock(path: string): void; /** * Imports module, bypassing all checks if it should be mocked. * Can be useful if you want to mock module partially. * @example * vi.mock('./example.js', async () => { * const axios = await vi.importActual('./example.js') * * return { ...axios, get: vi.fn() } * }) * @param path Path to the module. Can be aliased, if your config supports it */ importActual(path: string): Promise; /** * Imports a module with all of its properties and nested properties mocked. * * Mocking algorithm is described in [documentation](https://vitest.dev/guide/mocking#modules). * @example * const example = await vi.importMock('./example.js') * example.calc.mockReturnValue(10) * expect(example.calc()).toBe(10) * @param path Path to the module. Can be aliased, if your config supports it * @returns Fully mocked module */ importMock(path: string): Promise>; /** * Type helper for TypeScript. Just returns the object that was passed. * * When `partial` is `true` it will expect a `Partial` as a return value. By default, this will only make TypeScript believe that * the first level values are mocked. You can pass down `{ deep: true }` as a second argument to tell TypeScript that the whole object is mocked, if it actually is. * @example * import example from './example.js' * vi.mock('./example.js') * * test('1 + 1 equals 10' async () => { * vi.mocked(example.calc).mockReturnValue(10) * expect(example.calc(1, '+', 1)).toBe(10) * }) * @param item Anything that can be mocked * @param deep If the object is deeply mocked * @param options If the object is partially or deeply mocked */ mocked(item: T, deep?: false): MaybeMocked; mocked(item: T, deep: true): MaybeMockedDeep; mocked(item: T, options: { partial?: false; deep?: false; }): MaybeMocked; mocked(item: T, options: { partial?: false; deep: true; }): MaybeMockedDeep; mocked(item: T, options: { partial: true; deep?: false; }): MaybePartiallyMocked; mocked(item: T, options: { partial: true; deep: true; }): MaybePartiallyMockedDeep; mocked(item: T): MaybeMocked; /** * Checks that a given parameter is a mock function. If you are using TypeScript, it will also narrow down its type. */ isMockFunction(fn: any): fn is MockInstance; /** * Calls [`.mockClear()`](https://vitest.dev/api/mock#mockclear) on every mocked function. This will only empty `.mock` state, it will not reset implementation. * * It is useful if you need to clean up mock between different assertions. */ clearAllMocks(): VitestUtils; /** * Calls [`.mockReset()`](https://vitest.dev/api/mock#mockreset) on every mocked function. This will empty `.mock` state, reset "once" implementations and force the base implementation to return `undefined` when invoked. * * This is useful when you want to completely reset a mock to the default state. */ resetAllMocks(): VitestUtils; /** * Calls [`.mockRestore()`](https://vitest.dev/api/mock#mockrestore) on every mocked function. This will restore all original implementations. */ restoreAllMocks(): VitestUtils; /** * Makes value available on global namespace. * Useful, if you want to have global variables available, like `IntersectionObserver`. * You can return it back to original value with `vi.unstubAllGlobals`, or by enabling `unstubGlobals` config option. */ stubGlobal(name: string | symbol | number, value: unknown): VitestUtils; /** * Changes the value of `import.meta.env` and `process.env`. * You can return it back to original value with `vi.unstubAllEnvs`, or by enabling `unstubEnvs` config option. */ stubEnv(name: string, value: string): VitestUtils; /** * Reset the value to original value that was available before first `vi.stubGlobal` was called. */ unstubAllGlobals(): VitestUtils; /** * Reset environmental variables to the ones that were available before first `vi.stubEnv` was called. */ unstubAllEnvs(): VitestUtils; /** * Resets modules registry by clearing the cache of all modules. This allows modules to be reevaluated when reimported. * Top-level imports cannot be re-evaluated. Might be useful to isolate modules where local state conflicts between tests. * * This method does not reset mocks registry. To clear mocks registry, use [`vi.unmock`](https://vitest.dev/api/vi#vi-unmock) or [`vi.doUnmock`](https://vitest.dev/api/vi#vi-dounmock). */ resetModules(): VitestUtils; /** * Wait for all imports to load. Useful, if you have a synchronous call that starts * importing a module that you cannot await otherwise. * Will also wait for new imports, started during the wait. */ dynamicImportSettled(): Promise; /** * Updates runtime config. You can only change values that are used when executing tests. */ setConfig(config: RuntimeConfig): void; /** * If config was changed with `vi.setConfig`, this will reset it to the original state. */ resetConfig(): void; } declare const vitest: VitestUtils; declare const vi: VitestUtils; declare function getRunningMode(): "run" | "watch"; declare function isWatchMode(): boolean; /** * Gives access to injected context provided from the main thread. * This usually returns a value provided by `globalSetup` or an external library. */ declare function inject(key: T): ProvidedContext[T]; interface TransformResultWithSource extends TransformResult { source?: string; } interface WebSocketHandlers { onUnhandledError(error: unknown, type: string): Promise; onCollected(files?: File[]): Promise; onTaskUpdate(packs: TaskResultPack[]): void; onAfterSuiteRun(meta: AfterSuiteRunMeta): void; onDone(name: string): void; onCancel(reason: CancelReason): void; getCountOfFailedTests(): number; sendLog(log: UserConsoleLog): void; getFiles(): File[]; getPaths(): string[]; getConfig(): ResolvedConfig; resolveSnapshotPath(testPath: string): string; resolveSnapshotRawPath(testPath: string, rawPath: string): string; getModuleGraph(id: string): Promise; getTransformResult(id: string): Promise; readSnapshotFile(id: string): Promise; readTestFile(id: string): Promise; saveTestFile(id: string, content: string): Promise; saveSnapshotFile(id: string, content: string): Promise; removeSnapshotFile(id: string): Promise; snapshotSaved(snapshot: SnapshotResult): void; rerun(files: string[]): Promise; updateSnapshot(file?: File): Promise; getProvidedContext(): ProvidedContext; getUnhandledErrors(): unknown[]; } interface WebSocketEvents extends Pick { onCancel(reason: CancelReason): void; } export { AfterSuiteRunMeta, type AssertType, type ExpectTypeOf, ModuleGraphData, ProvidedContext, Reporter, ResolvedConfig, RuntimeConfig, type TransformResultWithSource, UserConsoleLog, type VitestUtils, type WebSocketEvents, type WebSocketHandlers, assertType, createExpect, globalExpect as expect, expectTypeOf, getRunningMode, inject, isFirstRun, isWatchMode, runOnce, vi, vitest };