@storybook/experimental-nextjs-vite 9.0.0-alpha.6 → 9.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { M as Mock } from '../../index.d-5a935e77.js';
1
+ import { M as Mock } from '../../index.d-98b9eb06.js';
2
2
 
3
3
  declare const revalidatePath: Mock<(...args: any[]) => any>;
4
4
  declare const revalidateTag: Mock<(...args: any[]) => any>;
@@ -1,4 +1,4 @@
1
- import { M as Mock } from '../../index.d-5a935e77.js';
1
+ import { M as Mock } from '../../index.d-98b9eb06.js';
2
2
  import { draftMode as draftMode$1 } from 'next/dist/server/request/draft-mode';
3
3
  export * from 'next/dist/server/request/headers';
4
4
  import { HeadersAdapter } from 'next/dist/server/web/spec-extension/adapters/headers';
@@ -1,4 +1,4 @@
1
- import { M as Mock$1 } from '../../index.d-5a935e77.js';
1
+ import { M as Mock$1 } from '../../index.d-98b9eb06.js';
2
2
  import * as actual from 'next/dist/client/components/navigation';
3
3
  export * from 'next/dist/client/components/navigation';
4
4
  import { Mock } from 'storybook/test';
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import * as next_dist_client_with_router from 'next/dist/client/with-router';
3
3
  import * as next from 'next';
4
- import { M as Mock$1 } from '../../index.d-5a935e77.js';
4
+ import { M as Mock$1 } from '../../index.d-98b9eb06.js';
5
5
  import * as singletonRouter from 'next/dist/client/router';
6
6
  import singletonRouter__default from 'next/dist/client/router';
7
7
  export * from 'next/dist/client/router';
@@ -0,0 +1,296 @@
1
+ interface MockResultReturn<T> {
2
+ type: "return";
3
+ /**
4
+ * The value that was returned from the function. If function returned a Promise, then this will be a resolved value.
5
+ */
6
+ value: T;
7
+ }
8
+ interface MockResultIncomplete {
9
+ type: "incomplete";
10
+ value: undefined;
11
+ }
12
+ interface MockResultThrow {
13
+ type: "throw";
14
+ /**
15
+ * An error that was thrown during function execution.
16
+ */
17
+ value: any;
18
+ }
19
+ interface MockSettledResultFulfilled<T> {
20
+ type: "fulfilled";
21
+ value: T;
22
+ }
23
+ interface MockSettledResultRejected {
24
+ type: "rejected";
25
+ value: any;
26
+ }
27
+ type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
28
+ type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected;
29
+ interface MockContext<T extends Procedure> {
30
+ /**
31
+ * This is an array containing all arguments for each call. One item of the array is the arguments of that call.
32
+ *
33
+ * @see https://vitest.dev/api/mock#mock-calls
34
+ * @example
35
+ * const fn = vi.fn()
36
+ *
37
+ * fn('arg1', 'arg2')
38
+ * fn('arg3')
39
+ *
40
+ * fn.mock.calls === [
41
+ * ['arg1', 'arg2'], // first call
42
+ * ['arg3'], // second call
43
+ * ]
44
+ */
45
+ calls: Parameters<T>[];
46
+ /**
47
+ * This is an array containing all instances that were instantiated when mock was called with a `new` keyword. Note that this is an actual context (`this`) of the function, not a return value.
48
+ * @see https://vitest.dev/api/mock#mock-instances
49
+ */
50
+ instances: ReturnType<T>[];
51
+ /**
52
+ * An array of `this` values that were used during each call to the mock function.
53
+ * @see https://vitest.dev/api/mock#mock-contexts
54
+ */
55
+ contexts: ThisParameterType<T>[];
56
+ /**
57
+ * The order of mock's execution. This returns an array of numbers which are shared between all defined mocks.
58
+ *
59
+ * @see https://vitest.dev/api/mock#mock-invocationcallorder
60
+ * @example
61
+ * const fn1 = vi.fn()
62
+ * const fn2 = vi.fn()
63
+ *
64
+ * fn1()
65
+ * fn2()
66
+ * fn1()
67
+ *
68
+ * fn1.mock.invocationCallOrder === [1, 3]
69
+ * fn2.mock.invocationCallOrder === [2]
70
+ */
71
+ invocationCallOrder: number[];
72
+ /**
73
+ * This is an array containing all values that were `returned` from the function.
74
+ *
75
+ * The `value` property contains the returned value or thrown error. If the function returned a `Promise`, then `result` will always be `'return'` even if the promise was rejected.
76
+ *
77
+ * @see https://vitest.dev/api/mock#mock-results
78
+ * @example
79
+ * const fn = vi.fn()
80
+ * .mockReturnValueOnce('result')
81
+ * .mockImplementationOnce(() => { throw new Error('thrown error') })
82
+ *
83
+ * const result = fn()
84
+ *
85
+ * try {
86
+ * fn()
87
+ * }
88
+ * catch {}
89
+ *
90
+ * fn.mock.results === [
91
+ * {
92
+ * type: 'return',
93
+ * value: 'result',
94
+ * },
95
+ * {
96
+ * type: 'throw',
97
+ * value: Error,
98
+ * },
99
+ * ]
100
+ */
101
+ results: MockResult<ReturnType<T>>[];
102
+ /**
103
+ * An array containing all values that were `resolved` or `rejected` from the function.
104
+ *
105
+ * This array will be empty if the function was never resolved or rejected.
106
+ *
107
+ * @see https://vitest.dev/api/mock#mock-settledresults
108
+ * @example
109
+ * const fn = vi.fn().mockResolvedValueOnce('result')
110
+ *
111
+ * const result = fn()
112
+ *
113
+ * fn.mock.settledResults === []
114
+ * fn.mock.results === [
115
+ * {
116
+ * type: 'return',
117
+ * value: Promise<'result'>,
118
+ * },
119
+ * ]
120
+ *
121
+ * await result
122
+ *
123
+ * fn.mock.settledResults === [
124
+ * {
125
+ * type: 'fulfilled',
126
+ * value: 'result',
127
+ * },
128
+ * ]
129
+ */
130
+ settledResults: MockSettledResult<Awaited<ReturnType<T>>>[];
131
+ /**
132
+ * This contains the arguments of the last call. If spy wasn't called, will return `undefined`.
133
+ * @see https://vitest.dev/api/mock#mock-lastcall
134
+ */
135
+ lastCall: Parameters<T> | undefined;
136
+ }
137
+ type Procedure = (...args: any[]) => any;
138
+ type NormalizedProcedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
139
+ interface MockInstance<T extends Procedure = Procedure> {
140
+ /**
141
+ * Use it to return the name assigned to the mock with the `.mockName(name)` method. By default, it will return `vi.fn()`.
142
+ * @see https://vitest.dev/api/mock#getmockname
143
+ */
144
+ getMockName(): string;
145
+ /**
146
+ * Sets the internal mock name. This is useful for identifying the mock when an assertion fails.
147
+ * @see https://vitest.dev/api/mock#mockname
148
+ */
149
+ mockName(name: string): this;
150
+ /**
151
+ * Current context of the mock. It stores information about all invocation calls, instances, and results.
152
+ */
153
+ mock: MockContext<T>;
154
+ /**
155
+ * Clears all information about every call. After calling it, all properties on `.mock` will return to their initial state. This method does not reset implementations. It is useful for cleaning up mocks between different assertions.
156
+ *
157
+ * To automatically call this method before each test, enable the [`clearMocks`](https://vitest.dev/config/#clearmocks) setting in the configuration.
158
+ * @see https://vitest.dev/api/mock#mockclear
159
+ */
160
+ mockClear(): this;
161
+ /**
162
+ * Does what `mockClear` does and resets inner implementation to the original function. This also resets all "once" implementations.
163
+ *
164
+ * Note that resetting a mock from `vi.fn()` will set implementation to an empty function that returns `undefined`.
165
+ * Resetting a mock from `vi.fn(impl)` will set implementation to `impl`. It is useful for completely resetting a mock to its default state.
166
+ *
167
+ * To automatically call this method before each test, enable the [`mockReset`](https://vitest.dev/config/#mockreset) setting in the configuration.
168
+ * @see https://vitest.dev/api/mock#mockreset
169
+ */
170
+ mockReset(): this;
171
+ /**
172
+ * Does what `mockReset` does and restores original descriptors of spied-on objects.
173
+ *
174
+ * Note that restoring mock from `vi.fn()` will set implementation to an empty function that returns `undefined`. Restoring a `vi.fn(impl)` will restore implementation to `impl`.
175
+ * @see https://vitest.dev/api/mock#mockrestore
176
+ */
177
+ mockRestore(): void;
178
+ /**
179
+ * Returns current permanent mock implementation if there is one.
180
+ *
181
+ * If mock was created with `vi.fn`, it will consider passed down method as a mock implementation.
182
+ *
183
+ * If mock was created with `vi.spyOn`, it will return `undefined` unless a custom implementation was provided.
184
+ */
185
+ getMockImplementation(): NormalizedProcedure<T> | undefined;
186
+ /**
187
+ * Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function.
188
+ * @see https://vitest.dev/api/mock#mockimplementation
189
+ * @example
190
+ * const increment = vi.fn().mockImplementation(count => count + 1);
191
+ * expect(increment(3)).toBe(4);
192
+ */
193
+ mockImplementation(fn: NormalizedProcedure<T>): this;
194
+ /**
195
+ * Accepts a function to be used as the mock implementation. TypeScript expects the arguments and return type to match those of the original function. This method can be chained to produce different results for multiple function calls.
196
+ *
197
+ * When the mocked function runs out of implementations, it will invoke the default implementation set with `vi.fn(() => defaultValue)` or `.mockImplementation(() => defaultValue)` if they were called.
198
+ * @see https://vitest.dev/api/mock#mockimplementationonce
199
+ * @example
200
+ * const fn = vi.fn(count => count).mockImplementationOnce(count => count + 1);
201
+ * expect(fn(3)).toBe(4);
202
+ * expect(fn(3)).toBe(3);
203
+ */
204
+ mockImplementationOnce(fn: NormalizedProcedure<T>): this;
205
+ /**
206
+ * Overrides the original mock implementation temporarily while the callback is being executed.
207
+ *
208
+ * Note that this method takes precedence over the [`mockImplementationOnce`](https://vitest.dev/api/mock#mockimplementationonce).
209
+ * @see https://vitest.dev/api/mock#withimplementation
210
+ * @example
211
+ * const myMockFn = vi.fn(() => 'original')
212
+ *
213
+ * myMockFn.withImplementation(() => 'temp', () => {
214
+ * myMockFn() // 'temp'
215
+ * })
216
+ *
217
+ * myMockFn() // 'original'
218
+ */
219
+ withImplementation<T2>(fn: NormalizedProcedure<T>, cb: () => T2): T2 extends Promise<unknown> ? Promise<this> : this;
220
+ /**
221
+ * Use this if you need to return the `this` context from the method without invoking the actual implementation.
222
+ * @see https://vitest.dev/api/mock#mockreturnthis
223
+ */
224
+ mockReturnThis(): this;
225
+ /**
226
+ * Accepts a value that will be returned whenever the mock function is called. TypeScript will only accept values that match the return type of the original function.
227
+ * @see https://vitest.dev/api/mock#mockreturnvalue
228
+ * @example
229
+ * const mock = vi.fn()
230
+ * mock.mockReturnValue(42)
231
+ * mock() // 42
232
+ * mock.mockReturnValue(43)
233
+ * mock() // 43
234
+ */
235
+ mockReturnValue(value: ReturnType<T>): this;
236
+ /**
237
+ * Accepts a value that will be returned whenever the mock function is called. TypeScript will only accept values that match the return type of the original function.
238
+ *
239
+ * When the mocked function runs out of implementations, it will invoke the default implementation set with `vi.fn(() => defaultValue)` or `.mockImplementation(() => defaultValue)` if they were called.
240
+ * @example
241
+ * const myMockFn = vi
242
+ * .fn()
243
+ * .mockReturnValue('default')
244
+ * .mockReturnValueOnce('first call')
245
+ * .mockReturnValueOnce('second call')
246
+ *
247
+ * // 'first call', 'second call', 'default'
248
+ * console.log(myMockFn(), myMockFn(), myMockFn())
249
+ */
250
+ mockReturnValueOnce(value: ReturnType<T>): this;
251
+ /**
252
+ * Accepts a value that will be resolved when the async function is called. TypeScript will only accept values that match the return type of the original function.
253
+ * @example
254
+ * const asyncMock = vi.fn().mockResolvedValue(42)
255
+ * asyncMock() // Promise<42>
256
+ */
257
+ mockResolvedValue(value: Awaited<ReturnType<T>>): this;
258
+ /**
259
+ * Accepts a value that will be resolved during the next function call. TypeScript will only accept values that match the return type of the original function. If chained, each consecutive call will resolve the specified value.
260
+ * @example
261
+ * const myMockFn = vi
262
+ * .fn()
263
+ * .mockResolvedValue('default')
264
+ * .mockResolvedValueOnce('first call')
265
+ * .mockResolvedValueOnce('second call')
266
+ *
267
+ * // Promise<'first call'>, Promise<'second call'>, Promise<'default'>
268
+ * console.log(myMockFn(), myMockFn(), myMockFn())
269
+ */
270
+ mockResolvedValueOnce(value: Awaited<ReturnType<T>>): this;
271
+ /**
272
+ * Accepts an error that will be rejected when async function is called.
273
+ * @example
274
+ * const asyncMock = vi.fn().mockRejectedValue(new Error('Async error'))
275
+ * await asyncMock() // throws Error<'Async error'>
276
+ */
277
+ mockRejectedValue(error: unknown): this;
278
+ /**
279
+ * Accepts a value that will be rejected during the next function call. If chained, each consecutive call will reject the specified value.
280
+ * @example
281
+ * const asyncMock = vi
282
+ * .fn()
283
+ * .mockResolvedValueOnce('first call')
284
+ * .mockRejectedValueOnce(new Error('Async error'))
285
+ *
286
+ * await asyncMock() // first call
287
+ * await asyncMock() // throws Error<'Async error'>
288
+ */
289
+ mockRejectedValueOnce(error: unknown): this;
290
+ }
291
+ interface Mock<T extends Procedure = Procedure> extends MockInstance<T> {
292
+ new (...args: Parameters<T>): ReturnType<T>;
293
+ (...args: Parameters<T>): ReturnType<T>;
294
+ }
295
+
296
+ export { Mock as M };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/experimental-nextjs-vite",
3
- "version": "9.0.0-alpha.6",
3
+ "version": "9.0.0-alpha.7",
4
4
  "description": "Storybook for Next.js and Vite",
5
5
  "keywords": [
6
6
  "storybook",
@@ -104,9 +104,9 @@
104
104
  "prep": "jiti ../../../scripts/prepare/bundle.ts"
105
105
  },
106
106
  "dependencies": {
107
- "@storybook/builder-vite": "9.0.0-alpha.6",
108
- "@storybook/react": "9.0.0-alpha.6",
109
- "@storybook/react-vite": "9.0.0-alpha.6",
107
+ "@storybook/builder-vite": "9.0.0-alpha.7",
108
+ "@storybook/react": "9.0.0-alpha.7",
109
+ "@storybook/react-vite": "9.0.0-alpha.7",
110
110
  "styled-jsx": "5.1.6",
111
111
  "vite-plugin-storybook-nextjs": "2.0.0--canary.33.a61ad85.0"
112
112
  },
@@ -119,7 +119,7 @@
119
119
  "next": "^14.1.0 || ^15.0.0",
120
120
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
121
121
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
122
- "storybook": "^9.0.0-alpha.6",
122
+ "storybook": "^9.0.0-alpha.7",
123
123
  "vite": "^5.0.0 || ^6.0.0"
124
124
  },
125
125
  "peerDependenciesMeta": {
@@ -1,266 +0,0 @@
1
- interface MockResultReturn<T> {
2
- type: 'return';
3
- /**
4
- * The value that was returned from the function. If function returned a Promise, then this will be a resolved value.
5
- */
6
- value: T;
7
- }
8
- interface MockResultIncomplete {
9
- type: 'incomplete';
10
- value: undefined;
11
- }
12
- interface MockResultThrow {
13
- type: 'throw';
14
- /**
15
- * An error that was thrown during function execution.
16
- */
17
- value: any;
18
- }
19
- interface MockSettledResultFulfilled<T> {
20
- type: 'fulfilled';
21
- value: T;
22
- }
23
- interface MockSettledResultRejected {
24
- type: 'rejected';
25
- value: any;
26
- }
27
- type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
28
- type MockSettledResult<T> = MockSettledResultFulfilled<T> | MockSettledResultRejected;
29
- interface MockContext<T extends Procedure> {
30
- /**
31
- * This is an array containing all arguments for each call. One item of the array is the arguments of that call.
32
- *
33
- * @example
34
- * const fn = vi.fn()
35
- *
36
- * fn('arg1', 'arg2')
37
- * fn('arg3')
38
- *
39
- * fn.mock.calls === [
40
- * ['arg1', 'arg2'], // first call
41
- * ['arg3'], // second call
42
- * ]
43
- */
44
- calls: Parameters<T>[];
45
- /**
46
- * This is an array containing all instances that were instantiated when mock was called with a `new` keyword. Note that this is an actual context (`this`) of the function, not a return value.
47
- */
48
- instances: ReturnType<T>[];
49
- /**
50
- * An array of `this` values that were used during each call to the mock function.
51
- */
52
- contexts: ThisParameterType<T>[];
53
- /**
54
- * The order of mock's execution. This returns an array of numbers which are shared between all defined mocks.
55
- *
56
- * @example
57
- * const fn1 = vi.fn()
58
- * const fn2 = vi.fn()
59
- *
60
- * fn1()
61
- * fn2()
62
- * fn1()
63
- *
64
- * fn1.mock.invocationCallOrder === [1, 3]
65
- * fn2.mock.invocationCallOrder === [2]
66
- */
67
- invocationCallOrder: number[];
68
- /**
69
- * This is an array containing all values that were `returned` from the function.
70
- *
71
- * The `value` property contains the returned value or thrown error. If the function returned a `Promise`, then `result` will always be `'return'` even if the promise was rejected.
72
- *
73
- * @example
74
- * const fn = vi.fn()
75
- * .mockReturnValueOnce('result')
76
- * .mockImplementationOnce(() => { throw new Error('thrown error') })
77
- *
78
- * const result = fn()
79
- *
80
- * try {
81
- * fn()
82
- * }
83
- * catch {}
84
- *
85
- * fn.mock.results === [
86
- * {
87
- * type: 'return',
88
- * value: 'result',
89
- * },
90
- * {
91
- * type: 'throw',
92
- * value: Error,
93
- * },
94
- * ]
95
- */
96
- results: MockResult<ReturnType<T>>[];
97
- /**
98
- * An array containing all values that were `resolved` or `rejected` from the function.
99
- *
100
- * This array will be empty if the function was never resolved or rejected.
101
- *
102
- * @example
103
- * const fn = vi.fn().mockResolvedValueOnce('result')
104
- *
105
- * const result = fn()
106
- *
107
- * fn.mock.settledResults === []
108
- * fn.mock.results === [
109
- * {
110
- * type: 'return',
111
- * value: Promise<'result'>,
112
- * },
113
- * ]
114
- *
115
- * await result
116
- *
117
- * fn.mock.settledResults === [
118
- * {
119
- * type: 'fulfilled',
120
- * value: 'result',
121
- * },
122
- * ]
123
- */
124
- settledResults: MockSettledResult<Awaited<ReturnType<T>>>[];
125
- /**
126
- * This contains the arguments of the last call. If spy wasn't called, will return `undefined`.
127
- */
128
- lastCall: Parameters<T> | undefined;
129
- }
130
- type Procedure = (...args: any[]) => any;
131
- type NormalizedPrecedure<T extends Procedure> = (...args: Parameters<T>) => ReturnType<T>;
132
- interface MockInstance<T extends Procedure = Procedure> {
133
- /**
134
- * Use it to return the name given to mock with method `.mockName(name)`.
135
- */
136
- getMockName(): string;
137
- /**
138
- * Sets internal mock name. Useful to see the name of the mock if an assertion fails.
139
- */
140
- mockName(n: string): this;
141
- /**
142
- * Current context of the mock. It stores information about all invocation calls, instances, and results.
143
- */
144
- mock: MockContext<T>;
145
- /**
146
- * Clears all information about every call. After calling it, all properties on `.mock` will return an empty state. This method does not reset implementations.
147
- *
148
- * It is useful if you need to clean up mock between different assertions.
149
- */
150
- mockClear(): this;
151
- /**
152
- * Does what `mockClear` does and makes inner implementation an empty function (returning `undefined` when invoked). This also resets all "once" implementations.
153
- *
154
- * This is useful when you want to completely reset a mock to the default state.
155
- */
156
- mockReset(): this;
157
- /**
158
- * Does what `mockReset` does and restores inner implementation to the original function.
159
- *
160
- * Note that restoring mock from `vi.fn()` will set implementation to an empty function that returns `undefined`. Restoring a `vi.fn(impl)` will restore implementation to `impl`.
161
- */
162
- mockRestore(): void;
163
- /**
164
- * Returns current mock implementation if there is one.
165
- *
166
- * If mock was created with `vi.fn`, it will consider passed down method as a mock implementation.
167
- *
168
- * If mock was created with `vi.spyOn`, it will return `undefined` unless a custom implementation was provided.
169
- */
170
- getMockImplementation(): NormalizedPrecedure<T> | undefined;
171
- /**
172
- * Accepts a function that will be used as an implementation of the mock.
173
- * @example
174
- * const increment = vi.fn().mockImplementation(count => count + 1);
175
- * expect(increment(3)).toBe(4);
176
- */
177
- mockImplementation(fn: NormalizedPrecedure<T>): this;
178
- /**
179
- * Accepts a function that will be used as a mock implementation during the next call. Can be chained so that multiple function calls produce different results.
180
- * @example
181
- * const fn = vi.fn(count => count).mockImplementationOnce(count => count + 1);
182
- * expect(fn(3)).toBe(4);
183
- * expect(fn(3)).toBe(3);
184
- */
185
- mockImplementationOnce(fn: NormalizedPrecedure<T>): this;
186
- /**
187
- * Overrides the original mock implementation temporarily while the callback is being executed.
188
- * @example
189
- * const myMockFn = vi.fn(() => 'original')
190
- *
191
- * myMockFn.withImplementation(() => 'temp', () => {
192
- * myMockFn() // 'temp'
193
- * })
194
- *
195
- * myMockFn() // 'original'
196
- */
197
- withImplementation<T2>(fn: NormalizedPrecedure<T>, cb: () => T2): T2 extends Promise<unknown> ? Promise<this> : this;
198
- /**
199
- * Use this if you need to return `this` context from the method without invoking actual implementation.
200
- */
201
- mockReturnThis(): this;
202
- /**
203
- * Accepts a value that will be returned whenever the mock function is called.
204
- */
205
- mockReturnValue(obj: ReturnType<T>): this;
206
- /**
207
- * Accepts a value that will be returned during the next function call. If chained, every consecutive call will return the specified value.
208
- *
209
- * When there are no more `mockReturnValueOnce` values to use, mock will fallback to the previously defined implementation if there is one.
210
- * @example
211
- * const myMockFn = vi
212
- * .fn()
213
- * .mockReturnValue('default')
214
- * .mockReturnValueOnce('first call')
215
- * .mockReturnValueOnce('second call')
216
- *
217
- * // 'first call', 'second call', 'default'
218
- * console.log(myMockFn(), myMockFn(), myMockFn())
219
- */
220
- mockReturnValueOnce(obj: ReturnType<T>): this;
221
- /**
222
- * Accepts a value that will be resolved when async function is called.
223
- * @example
224
- * const asyncMock = vi.fn().mockResolvedValue(42)
225
- * asyncMock() // Promise<42>
226
- */
227
- mockResolvedValue(obj: Awaited<ReturnType<T>>): this;
228
- /**
229
- * Accepts a value that will be resolved during the next function call. If chained, every consecutive call will resolve specified value.
230
- * @example
231
- * const myMockFn = vi
232
- * .fn()
233
- * .mockResolvedValue('default')
234
- * .mockResolvedValueOnce('first call')
235
- * .mockResolvedValueOnce('second call')
236
- *
237
- * // Promise<'first call'>, Promise<'second call'>, Promise<'default'>
238
- * console.log(myMockFn(), myMockFn(), myMockFn())
239
- */
240
- mockResolvedValueOnce(obj: Awaited<ReturnType<T>>): this;
241
- /**
242
- * Accepts an error that will be rejected when async function is called.
243
- * @example
244
- * const asyncMock = vi.fn().mockRejectedValue(new Error('Async error'))
245
- * await asyncMock() // throws 'Async error'
246
- */
247
- mockRejectedValue(obj: any): this;
248
- /**
249
- * Accepts a value that will be rejected during the next function call. If chained, every consecutive call will reject specified value.
250
- * @example
251
- * const asyncMock = vi
252
- * .fn()
253
- * .mockResolvedValueOnce('first call')
254
- * .mockRejectedValueOnce(new Error('Async error'))
255
- *
256
- * await asyncMock() // first call
257
- * await asyncMock() // throws "Async error"
258
- */
259
- mockRejectedValueOnce(obj: any): this;
260
- }
261
- interface Mock<T extends Procedure = Procedure> extends MockInstance<T> {
262
- new (...args: Parameters<T>): ReturnType<T>;
263
- (...args: Parameters<T>): ReturnType<T>;
264
- }
265
-
266
- export { Mock as M };