@nuxt/test-utils-nightly 3.20.8-20251025-050337-8ff5393 → 3.21.0-20251030-161832-4f04851

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.
@@ -78,9 +78,6 @@ export async function setupWindow(win, environmentOptions) {
78
78
  return _fetch(input, _init);
79
79
  };
80
80
  win.$fetch = createFetch({ fetch: win.fetch, Headers: win.Headers });
81
- win.$fetch.create = (options = {}) => {
82
- return createFetch({ fetch: win.fetch, Headers: win.Headers, ...options });
83
- };
84
81
  win.__registry = registry;
85
82
  win.__app = h3App;
86
83
  const timestamp = Date.now();
@@ -7,9 +7,33 @@ import { RenderOptions as RenderOptions$1 } from '@testing-library/vue';
7
7
 
8
8
  type Awaitable<T> = T | Promise<T>;
9
9
  type OptionalFunction<T> = T | (() => Awaitable<T>);
10
+ /**
11
+ * `registerEndpoint` allows you create Nitro endpoint that returns mocked data. It can come in handy if you want to test a component that makes requests to API to display some data.
12
+ * @param url - endpoint name (e.g. `/test/`).
13
+ * @param options - factory function that returns the mocked data or an object containing the `handler`, `method`, and `once` properties.
14
+ * - `handler`: the event handler function
15
+ * - `method`: (optional) HTTP method to match (e.g., 'GET', 'POST')
16
+ * - `once`: (optional) if true, the handler will only be used for the first matching request and then automatically removed
17
+ * @example
18
+ * ```ts
19
+ * import { registerEndpoint } from '@nuxt/test-utils/runtime'
20
+ *
21
+ * registerEndpoint("/test/", () => ({
22
+ * test: "test-field"
23
+ * }))
24
+ *
25
+ * // With once option
26
+ * registerEndpoint("/api/user", {
27
+ * handler: () => ({ name: "Alice" }),
28
+ * once: true
29
+ * })
30
+ * ```
31
+ * @see https://nuxt.com/docs/getting-started/testing#registerendpoint
32
+ */
10
33
  declare function registerEndpoint(url: string, options: EventHandler | {
11
34
  handler: EventHandler;
12
- method: HTTPMethod;
35
+ method?: HTTPMethod;
36
+ once?: boolean;
13
37
  }): () => void;
14
38
  /**
15
39
  * `mockNuxtImport` allows you to mock Nuxt's auto import functionality.
@@ -11,16 +11,25 @@ function registerEndpoint(url, options) {
11
11
  if (!app) {
12
12
  throw new Error("registerEndpoint() can only be used in a `@nuxt/test-utils` runtime environment");
13
13
  }
14
- const config = typeof options === "function" ? { handler: options, method: void 0 } : options;
14
+ const config = typeof options === "function" ? { handler: options, method: void 0, once: false } : options;
15
15
  config.handler = defineEventHandler(config.handler);
16
16
  const hasBeenRegistered = window.__registry.has(url);
17
17
  endpointRegistry[url] ||= [];
18
18
  endpointRegistry[url].push(config);
19
19
  if (!hasBeenRegistered) {
20
20
  window.__registry.add(url);
21
- app.use("/_" + url, defineEventHandler((event) => {
21
+ app.use("/_" + url, defineEventHandler(async (event) => {
22
22
  const latestHandler = [...endpointRegistry[url] || []].reverse().find((config2) => config2.method ? event.method === config2.method : true);
23
- return latestHandler?.handler(event);
23
+ if (!latestHandler) return;
24
+ const result = await latestHandler.handler(event);
25
+ if (!latestHandler.once) return result;
26
+ const index = endpointRegistry[url]?.indexOf(latestHandler);
27
+ if (index === void 0 || index === -1) return result;
28
+ endpointRegistry[url]?.splice(index, 1);
29
+ if (endpointRegistry[url]?.length === 0) {
30
+ window.__registry.delete(url);
31
+ }
32
+ return result;
24
33
  }), {
25
34
  match(_, event) {
26
35
  return endpointRegistry[url]?.some((config2) => config2.method ? event?.method === config2.method : true) ?? false;
@@ -325,6 +334,7 @@ async function renderSuspended(component, options) {
325
334
  const { render, setup, data, computed, methods } = component;
326
335
  let setupContext;
327
336
  let setupState;
337
+ const setProps = reactive({});
328
338
  let interceptedEmit = null;
329
339
  function getInterceptedEmitFunction(emit) {
330
340
  if (emit !== interceptedEmit) {
@@ -390,6 +400,10 @@ async function renderSuspended(component, options) {
390
400
  {
391
401
  onResolve: () => nextTick().then(() => {
392
402
  utils.setupState = setupState;
403
+ utils.rerender = async (props2) => {
404
+ Object.assign(setProps, props2);
405
+ await nextTick();
406
+ };
393
407
  resolve(utils);
394
408
  })
395
409
  },
@@ -449,7 +463,7 @@ async function renderSuspended(component, options) {
449
463
  } : void 0,
450
464
  setup: (props2) => wrappedSetup(props2, setupContext)
451
465
  };
452
- return () => h$1(clonedComponent, { ...props && typeof props === "object" ? props : {}, ...attrs }, slots);
466
+ return () => h$1(clonedComponent, { ...props && typeof props === "object" ? props : {}, ...setProps, ...attrs }, slots);
453
467
  }
454
468
  })
455
469
  }
@@ -83,9 +83,6 @@ async function setupWindow(win, environmentOptions) {
83
83
  return _fetch(input, _init);
84
84
  };
85
85
  win.$fetch = createFetch({ fetch: win.fetch, Headers: win.Headers });
86
- win.$fetch.create = (options = {}) => {
87
- return createFetch({ fetch: win.fetch, Headers: win.Headers, ...options });
88
- };
89
86
  win.__registry = registry;
90
87
  win.__app = h3App;
91
88
  const timestamp = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/test-utils-nightly",
3
- "version": "3.20.8-20251025-050337-8ff5393",
3
+ "version": "3.21.0-20251030-161832-4f04851",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/test-utils.git"
@@ -77,7 +77,7 @@
77
77
  "get-port-please": "^3.2.0",
78
78
  "h3": "^1.15.4",
79
79
  "local-pkg": "^1.1.2",
80
- "magic-string": "^0.30.19",
80
+ "magic-string": "^0.30.21",
81
81
  "node-fetch-native": "^1.6.7",
82
82
  "node-mock-http": "^1.0.3",
83
83
  "ofetch": "^1.4.1",
@@ -95,12 +95,12 @@
95
95
  "devDependencies": {
96
96
  "@cucumber/cucumber": "12.2.0",
97
97
  "@jest/globals": "30.2.0",
98
- "@nuxt/devtools-kit": "2.6.5",
98
+ "@nuxt/devtools-kit": "2.7.0",
99
99
  "@nuxt/eslint-config": "1.9.0",
100
100
  "@nuxt/schema": "4.1.3",
101
101
  "@playwright/test": "1.56.1",
102
102
  "@testing-library/vue": "8.1.0",
103
- "@types/bun": "1.3.0",
103
+ "@types/bun": "1.3.1",
104
104
  "@types/estree": "1.0.8",
105
105
  "@types/jsdom": "27.0.0",
106
106
  "@types/node": "latest",
@@ -110,8 +110,8 @@
110
110
  "compatx": "0.2.0",
111
111
  "eslint": "9.38.0",
112
112
  "installed-check": "9.3.0",
113
- "knip": "5.66.2",
114
- "nitropack": "2.12.7",
113
+ "knip": "5.66.3",
114
+ "nitropack": "2.12.8",
115
115
  "nuxt": "4.1.3",
116
116
  "pkg-pr-new": "0.0.60",
117
117
  "playwright-core": "1.56.1",
@@ -120,10 +120,10 @@
120
120
  "typescript": "5.9.3",
121
121
  "unbuild": "latest",
122
122
  "unimport": "5.5.0",
123
- "vite": "7.1.11",
123
+ "vite": "7.1.12",
124
124
  "vitest": "3.2.4",
125
125
  "vue-router": "4.6.3",
126
- "vue-tsc": "3.1.1"
126
+ "vue-tsc": "3.1.2"
127
127
  },
128
128
  "peerDependencies": {
129
129
  "@cucumber/cucumber": "^10.3.1 || >=11.0.0",
@@ -175,7 +175,7 @@
175
175
  "@nuxt/test-utils": "workspace:*",
176
176
  "@types/node": "22.18.8",
177
177
  "rollup": "4.52.5",
178
- "vite": "7.1.11",
178
+ "vite": "7.1.12",
179
179
  "vite-node": "3.2.4",
180
180
  "vitest": "3.2.4",
181
181
  "vue": "^3.5.22"
@@ -183,17 +183,5 @@
183
183
  "engines": {
184
184
  "node": "^20.0.0 || ^22.0.0 || >=24.0.0"
185
185
  },
186
- "packageManager": "pnpm@10.18.3",
187
- "pnpm": {
188
- "onlyBuiltDependencies": [
189
- "@tailwindcss/oxide",
190
- "better-sqlite3"
191
- ],
192
- "ignoredBuiltDependencies": [
193
- "esbuild",
194
- "oxc-resolver",
195
- "unrs-resolver",
196
- "vue-demi"
197
- ]
198
- }
186
+ "packageManager": "pnpm@10.19.0"
199
187
  }