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/README.md +46 -15
- package/README.zh-TW.md +274 -0
- package/dist/browser.cjs +5 -4
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +2 -1
- package/dist/{chunk-OSKJXLRH.cjs → chunk-27BEAYUI.cjs} +4 -4
- package/dist/chunk-3RE2WWHX.cjs +1 -0
- package/dist/{chunk-3RAWYKAG.js → chunk-3XFP4NAO.js} +30 -0
- package/dist/chunk-GZFGTCZB.js +0 -0
- package/dist/{chunk-NFPFLI3N.js → chunk-IWHL7QPE.js} +1 -1
- package/dist/{chunk-N6B7UP6B.cjs → chunk-VUNESK75.cjs} +30 -0
- package/dist/{fetch-mock-DhiqmHdF.d.cts → fetch-mock-1oOS8WUJ.d.cts} +31 -1
- package/dist/{fetch-mock-DhiqmHdF.d.ts → fetch-mock-1oOS8WUJ.d.ts} +31 -1
- package/dist/index.cjs +4 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/legacy.cjs +5 -5
- package/dist/legacy.d.cts +2 -2
- package/dist/legacy.d.ts +2 -2
- package/dist/legacy.js +1 -1
- package/dist/native.cjs +92 -0
- package/dist/native.d.cts +20 -0
- package/dist/native.d.ts +20 -0
- package/dist/native.js +92 -0
- package/dist/node.cjs +4 -3
- package/dist/node.d.cts +14 -2
- package/dist/node.d.ts +14 -2
- package/dist/node.js +3 -2
- package/docs/api.md +35 -10
- package/docs/api.zh-TW.md +707 -0
- package/docs/cloudflare-migration.zh-TW.md +80 -0
- package/docs/msw-v1-legacy.zh-TW.md +94 -0
- package/package.json +15 -1
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/
|
|
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` |
|
|
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
|
|