···13351335```
1336133613371337If [`vi.setConfig`](#vi-setconfig) was called before, this will reset config to the original state.
13381338+13391339+### vi.defineHelper <Version>4.1.0</Version> {#vi-defineHelper}
13401340+13411341+```ts
13421342+function defineHelper<F extends (...args: any) => any>(fn: F): F
13431343+```
13441344+13451345+Wraps a function to create an assertion helper. When an assertion fails inside the helper, the error stack trace will point to where the helper was called, not inside the helper itself. This makes it easier to identify the source of test failures when using custom assertion functions.
13461346+13471347+Works with both synchronous and asynchronous functions, and supports `expect.soft()`.
13481348+13491349+```ts
13501350+import { expect, vi } from 'vitest'
13511351+13521352+const assertPair = vi.defineHelper((a, b) => {
13531353+ expect(a).toEqual(b)
13541354+})
13551355+13561356+test('example', () => {
13571357+ assertPair('left', 'right') // Error points to this line
13581358+})
13591359+```
13601360+13611361+Example output:
13621362+13631363+<!-- eslint-skip -->
13641364+```js
13651365+FAIL example.test.ts > example
13661366+AssertionError: expected 'left' to deeply equal 'right'
13671367+13681368+Expected: "right"
13691369+Received: "left"
13701370+13711371+ ❯ example.test.ts:8:3
13721372+ 7| test('example', () => {
13731373+ 8| assertPair('left', 'right')
13741374+ | ^
13751375+ 9| })
13761376+```
···169169 waitFor: typeof waitFor
170170171171 /**
172172+ * Wraps a function to create an assertion helper. When an assertion fails inside the helper,
173173+ * the error stack trace will point to where the helper was called, not inside the helper itself.
174174+ * Works with both synchronous and asynchronous functions, and supports `expect.soft()`.
175175+ *
176176+ * @example
177177+ * ```ts
178178+ * const myEqual = vi.defineHelper((x, y) => {
179179+ * expect(x).toEqual(y)
180180+ * })
181181+ *
182182+ * test('example', () => {
183183+ * myEqual('left', 'right') // Error points to this line
184184+ * })
185185+ * ```
186186+ * Example output:
187187+ * ```
188188+ * FAIL example.test.ts > example
189189+ * AssertionError: expected 'left' to deeply equal 'right'
190190+ *
191191+ * Expected: "right"
192192+ * Received: "left"
193193+ *
194194+ * ❯ example.test.ts:6:3
195195+ * 4| test('example', () => {
196196+ * 5| myEqual('left', 'right')
197197+ * | ^
198198+ * 6| })
199199+ * ```
200200+ * @param fn The assertion function to wrap
201201+ * @returns A wrapped function with the same signature
202202+ */
203203+ defineHelper: <F extends (...args: any) => any>(fn: F) => F
204204+205205+ /**
172206 * 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.
173207 *
174208 * 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.
···576610 fn,
577611 waitFor,
578612 waitUntil,
613613+ defineHelper: (fn) => {
614614+ return function __VITEST_HELPER__(...args: any[]): any {
615615+ const result = fn(...args)
616616+ if (result && typeof result === 'object' && typeof result.then === 'function') {
617617+ return (async function __VITEST_HELPER__() {
618618+ return await result
619619+ })()
620620+ }
621621+ return result
622622+ } as any
623623+ },
579624 hoisted<T>(factory: () => T): T {
580625 assertTypes(factory, '"vi.hoisted" factory', ['function'])
581626 return factory()