@nuxt/docs-nightly 4.4.0-29546548.717c5fbf → 4.4.0-29546791.902eab24

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.
@@ -300,6 +300,10 @@ it('can also mount an app', async () => {
300
300
  })
301
301
  ```
302
302
 
303
+ The options object accepts `@vue/test-utils` mount options and the following properties:
304
+
305
+ - `route`: the initial route, or `false` to skip the initial route change (default `/`).
306
+
303
307
  #### `renderSuspended`
304
308
 
305
309
  `renderSuspended` allows you to render any Vue component within the Nuxt environment using `@testing-library/vue`, allowing async setup and access to injections from your Nuxt plugins.
@@ -352,6 +356,10 @@ it('can also render an app', async () => {
352
356
  })
353
357
  ```
354
358
 
359
+ The options object accepts `@testing-library/vue` render options and the following properties:
360
+
361
+ - `route`: the initial route, or `false` to skip the initial route change (default `/`).
362
+
355
363
  #### `mockNuxtImport`
356
364
 
357
365
  `mockNuxtImport` allows you to mock Nuxt's auto import functionality. For example, to mock `useStorage`, you can do so like this:
@@ -368,6 +376,27 @@ mockNuxtImport('useStorage', () => {
368
376
  // your tests here
369
377
  ```
370
378
 
379
+ You can explicitly type the mock for type safety, and use the original implementation passed to the factory function when mocking complex functionality.
380
+
381
+ ```ts twoslash
382
+ import { mockNuxtImport } from '@nuxt/test-utils/runtime'
383
+
384
+ mockNuxtImport<typeof useStorage>('useStorage', (original) => {
385
+ return (...args) => {
386
+ return { ...original(...args), value: 'mocked storage' }
387
+ }
388
+ })
389
+
390
+ // or specify the target to mock
391
+ mockNuxtImport(useStorage, (original) => {
392
+ return (...args) => {
393
+ return { ...original(...args), value: 'mocked storage' }
394
+ }
395
+ })
396
+
397
+ // your tests here
398
+ ```
399
+
371
400
  ::note
372
401
  `mockNuxtImport` can only be used once per mocked import per test file. It is actually a macro that gets transformed to `vi.mock` and `vi.mock` is hoisted, as described [in the Vitest docs](https://vitest.dev/api/vi#vi-mock).
373
402
  ::
@@ -396,6 +425,25 @@ useStorageMock.mockImplementation(() => {
396
425
  })
397
426
  ```
398
427
 
428
+ If you need to mock behavior only inside a test, you can also use the following approach.
429
+
430
+ ```ts twoslash
431
+ import { beforeEach, vi } from 'vitest'
432
+ import { mockNuxtImport } from '@nuxt/test-utils/runtime'
433
+
434
+ mockNuxtImport(useRoute, original => vi.fn(original))
435
+
436
+ beforeEach(() => {
437
+ vi.resetAllMocks()
438
+ })
439
+
440
+ // Then, inside a test
441
+ const useRouteOriginal = vi.mocked(useRoute).getMockImplementation()!
442
+ vi.mocked(useRoute).mockImplementation(
443
+ (...args) => ({ ...useRouteOriginal(...args), path: '/mocked' }),
444
+ )
445
+ ```
446
+
399
447
  #### `mockComponent`
400
448
 
401
449
  `mockComponent` allows you to mock Nuxt's component.
@@ -477,6 +525,12 @@ registerEndpoint('/test/', {
477
525
  })
478
526
  ```
479
527
 
528
+ This object accepts the following properties:
529
+
530
+ - `handler`: the event handler function
531
+ - `method`: (optional) HTTP method to match (e.g., 'GET', 'POST')
532
+ - `once`: (optional) if true, the handler will only be used for the first matching request and then automatically removed
533
+
480
534
  > **Note**: If your requests in a component go to an external API, you can use `baseURL` and then make it empty using [Nuxt Environment Override Config](/docs/4.x/getting-started/configuration#environment-overrides) (`$test`) so all your requests will go to Nitro server.
481
535
 
482
536
  #### Conflict with End-To-End Testing
@@ -161,6 +161,7 @@ type AsyncDataRequestContext = {
161
161
 
162
162
  type AsyncData<DataT, ErrorT> = {
163
163
  data: Ref<DataT | undefined>
164
+ pending: Ref<boolean>
164
165
  refresh: (opts?: AsyncDataExecuteOptions) => Promise<void>
165
166
  execute: (opts?: AsyncDataExecuteOptions) => Promise<void>
166
167
  clear: () => void
@@ -229,6 +230,7 @@ This only caches data when `experimental.payloadExtraction` in `nuxt.config` is
229
230
  | `execute` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Alias for `refresh`. |
230
231
  | `error` | `Ref<ErrorT \| undefined>` | Error object if the data fetching failed. |
231
232
  | `status` | `Ref<'idle' \| 'pending' \| 'success' \| 'error'>` | Status of the data request. See below for possible values. |
233
+ | `pending` | `Ref<boolean>` | Boolean flag indicating whether the current request is in progress. |
232
234
  | `clear` | `() => void` | Resets `data` to `undefined` (or the value of `options.default()` if provided), `error` to `undefined`, set `status` to `idle`, and cancels any pending requests. |
233
235
 
234
236
  ### Status values
@@ -76,6 +76,7 @@ Returns the same `AsyncData` object as [`useFetch`](/docs/4.x/api/composables/us
76
76
  | `execute` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Alias for `refresh`. |
77
77
  | `error` | `Ref<ErrorT \| undefined>` | Error object if the data fetching failed. |
78
78
  | `status` | `Ref<'idle' \| 'pending' \| 'success' \| 'error'>` | Status of the data request. |
79
+ | `pending` | `Ref<boolean>` | Boolean flag indicating whether the current request is in progress. |
79
80
  | `clear` | `() => void` | Resets `data` to `undefined`, `error` to `undefined`, sets `status` to `idle`, and cancels any pending requests. |
80
81
 
81
82
  :read-more{to="/docs/4.x/api/composables/use-fetch#return-values"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/docs-nightly",
3
- "version": "4.4.0-29546548.717c5fbf",
3
+ "version": "4.4.0-29546791.902eab24",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",