msw-fetch-mock 0.3.3 → 0.4.0

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/docs/api.md CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  ## Import Paths
4
4
 
5
- | Path | Environment | MSW version |
6
- | ------------------------ | ---------------------------- | ----------- |
7
- | `msw-fetch-mock` | Node.js (re-exports `/node`) | v2 |
8
- | `msw-fetch-mock/node` | Node.js | v2 |
9
- | `msw-fetch-mock/browser` | Browser | v2 |
10
- | `msw-fetch-mock/legacy` | Node.js (MSW v1) | v1 |
5
+ | Path | Environment | MSW version |
6
+ | ------------------------ | ---------------------------- | ------------ |
7
+ | `msw-fetch-mock` | Node.js (re-exports `/node`) | v2 |
8
+ | `msw-fetch-mock/node` | Node.js | v2 |
9
+ | `msw-fetch-mock/browser` | Browser | v2 |
10
+ | `msw-fetch-mock/native` | Any (no MSW) | not required |
11
+ | `msw-fetch-mock/legacy` | Node.js (MSW v1) | v1 |
11
12
 
12
13
  ## `fetchMock` (singleton)
13
14
 
@@ -58,6 +59,26 @@ beforeAll(async () => {
58
59
  });
59
60
  ```
60
61
 
62
+ ## `createFetchMock()` (Native)
63
+
64
+ Creates a `FetchMock` with `NativeFetchAdapter`. No MSW dependency required — patches `globalThis.fetch` directly.
65
+
66
+ ```typescript
67
+ import { createFetchMock } from 'msw-fetch-mock/native';
68
+
69
+ const fetchMock = createFetchMock();
70
+
71
+ beforeAll(async () => {
72
+ await fetchMock.activate({ onUnhandledRequest: 'error' });
73
+ });
74
+ ```
75
+
76
+ A pre-built singleton is also available:
77
+
78
+ ```typescript
79
+ import { fetchMock } from 'msw-fetch-mock/native';
80
+ ```
81
+
61
82
  ## `createFetchMock(rest, server?)` (Legacy)
62
83
 
63
84
  Creates a `FetchMock` for MSW v1 environments. See [MSW v1 Legacy Guide](msw-v1-legacy.md).
@@ -79,12 +100,16 @@ Creates a `FetchMock` instance with an explicit `MswAdapter`.
79
100
  import { FetchMock } from 'msw-fetch-mock';
80
101
  import { NodeMswAdapter } from 'msw-fetch-mock/node';
81
102
  import { BrowserMswAdapter } from 'msw-fetch-mock/browser';
103
+ import { NativeFetchAdapter } from 'msw-fetch-mock/native';
82
104
 
83
105
  // Node with external server
84
106
  const fetchMock = new FetchMock(new NodeMswAdapter(server));
85
107
 
86
108
  // Browser with worker
87
109
  const fetchMock = new FetchMock(new BrowserMswAdapter(worker));
110
+
111
+ // Native (no MSW)
112
+ const fetchMock = new FetchMock(new NativeFetchAdapter());
88
113
  ```
89
114
 
90
115
  | Parameter | Type | Required | Description |
@@ -425,7 +450,7 @@ Returns: `MockReplyChain`
425
450
  | `callback` | `SingleReplyCallback` | Full-control callback |
426
451
  | `options` | `{ headers?: Record<string, string> }` | Response headers |
427
452
 
428
- ### `interceptor.replyWithError(error)`
453
+ ### `interceptor.replyWithError(error?)`
429
454
 
430
455
  Replies with a network error (simulates a connection failure).
431
456
 
@@ -435,9 +460,9 @@ Replies with a network error (simulates a connection failure).
435
460
 
436
461
  Returns: `MockReplyChain`
437
462
 
438
- | Parameter | Type | Description |
439
- | --------- | ------- | ---------------------------------------- |
440
- | `error` | `Error` | The error instance (used for semantics). |
463
+ | Parameter | Type | Required | Description |
464
+ | --------- | ------- | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
465
+ | `error` | `Error` | No | Optional error instance. Accepted for API compatibility but not used internally — the response is always a generic network error. |
441
466
 
442
467
  ---
443
468