@storybook/nextjs 9.0.0-alpha.2 → 9.0.0-alpha.20
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.
- package/dist/export-mocks/cache/index.d.ts +1 -1
- package/dist/export-mocks/cache/index.js +1 -1
- package/dist/export-mocks/cache/index.mjs +1 -1
- package/dist/export-mocks/headers/index.d.ts +1 -1
- package/dist/export-mocks/headers/index.js +1 -1
- package/dist/export-mocks/headers/index.mjs +1 -1
- package/dist/export-mocks/index.js +1 -1
- package/dist/export-mocks/index.mjs +2 -2
- package/dist/export-mocks/navigation/index.d.ts +2 -2
- package/dist/export-mocks/navigation/index.js +1 -1
- package/dist/export-mocks/navigation/index.mjs +1 -1
- package/dist/export-mocks/router/index.d.ts +2 -2
- package/dist/export-mocks/router/index.js +1 -1
- package/dist/export-mocks/router/index.mjs +1 -1
- package/dist/index.d-98b9eb06.d.ts +296 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +3 -3
- package/dist/next-image-loader-stub.js +1 -2
- package/dist/next-image-loader-stub.mjs +3 -6
- package/dist/preset.js +1 -1
- package/package.json +8 -12
- package/template/cli/js/Button.jsx +0 -2
- package/template/cli/js/Button.stories.js +1 -1
- package/template/cli/js/Configure.mdx +1 -1
- package/template/cli/js/Header.jsx +0 -2
- package/template/cli/js/Header.stories.js +1 -1
- package/template/cli/js/Page.stories.js +1 -1
- package/template/cli/ts-4-9/Button.stories.ts +3 -2
- package/template/cli/ts-4-9/Button.tsx +0 -2
- package/template/cli/ts-4-9/Configure.mdx +1 -1
- package/template/cli/ts-4-9/Header.stories.ts +3 -2
- package/template/cli/ts-4-9/Header.tsx +0 -2
- package/template/cli/ts-4-9/Page.stories.ts +3 -2
- package/dist/index.d-5a935e77.d.ts +0 -266
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/
|
|
2
|
-
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/nextjs';
|
|
2
|
+
|
|
3
|
+
import { expect, userEvent, within } from 'storybook/test';
|
|
3
4
|
|
|
4
5
|
import { Page } from './Page';
|
|
5
6
|
|
|
@@ -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 };
|