@leaflink/dom-testing-utils 0.0.0-PR-309--aa80a65 → 0.0.0-PR-313--bdb408d
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 +42 -6
- package/dist/utils/__tests__/mockEndpoints.spec.d.ts +1 -0
- package/dist/utils/__tests__/mockEndpoints.spec.js +141 -0
- package/dist/utils/__tests__/mockEndpoints.spec.js.map +1 -0
- package/dist/utils/mockEndpoints.d.ts +14 -13
- package/dist/utils/mockEndpoints.js +1 -1
- package/dist/utils/mockEndpoints.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -315,6 +315,33 @@ const mockProducts = generateProducts(10, { cases: 25 });
|
|
|
315
315
|
|
|
316
316
|
In order to mock API endpoints that your tests interact with, you can get a set of mocking functions from `createMockApiUtils`.
|
|
317
317
|
|
|
318
|
+
These utilities use **MSW 3** and require Node.js 24 or newer (this package's existing minimum).
|
|
319
|
+
Consumers upgrading from MSW 2 must also migrate their server setup and handlers;
|
|
320
|
+
see the [MSW 2.x to 3.x migration guide](https://mswjs.io/docs/migrations/2.x-to-3.x).
|
|
321
|
+
Import HTTP APIs from `msw/http` and use `onUnhandledFrame` instead of `onUnhandledRequest`:
|
|
322
|
+
|
|
323
|
+
```ts
|
|
324
|
+
// server.ts
|
|
325
|
+
import { setupServer } from 'msw/node';
|
|
326
|
+
|
|
327
|
+
export default setupServer();
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
// In a test suite using the native fetch API:
|
|
332
|
+
import { afterAll, afterEach, beforeAll } from 'vitest';
|
|
333
|
+
import server from './server.ts';
|
|
334
|
+
|
|
335
|
+
beforeAll(() => server.listen({ onUnhandledFrame: 'error' }));
|
|
336
|
+
afterEach(() => server.resetHandlers());
|
|
337
|
+
afterAll(() => server.close());
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
The optional `setup-env` entrypoint stubs `fetch` before each test. For tests that
|
|
341
|
+
need MSW to intercept `fetch`, restore the native fetch implementation before
|
|
342
|
+
calling `server.listen()` in `beforeEach`, and close the server in `afterEach`.
|
|
343
|
+
Do not replace MSW's intercepted fetch with a mock.
|
|
344
|
+
|
|
318
345
|
```ts
|
|
319
346
|
import { createMockApiUtils } from '@leaflink/dom-testing-utils';
|
|
320
347
|
import yourServer from './server.ts';
|
|
@@ -330,7 +357,14 @@ const {
|
|
|
330
357
|
There are two flavors of mocking utility functions:
|
|
331
358
|
|
|
332
359
|
1. mock{VERB}Data - mocks response with a singular data object
|
|
333
|
-
2. mock{VERB}Endpoint - mocks a response endpoint with
|
|
360
|
+
2. mock{VERB}Endpoint - mocks a response endpoint with an MSW [HTTP response resolver](https://mswjs.io/docs/api/http#resolver-argument)
|
|
361
|
+
|
|
362
|
+
Both flavors support GET, POST, PUT, DELETE, and PATCH. The generic
|
|
363
|
+
`mockEndpointData(url, data, method, options?)` and
|
|
364
|
+
`mockEndpoint(url, resolver, method, options?)` helpers also accept `head`,
|
|
365
|
+
`options`, and `all`. The optional handler options (for example, `{ once: true }`)
|
|
366
|
+
are forwarded to MSW unchanged. New handlers override earlier handlers for the
|
|
367
|
+
same endpoint until `server.resetHandlers()` is called.
|
|
334
368
|
|
|
335
369
|
To mock an endpoint with simple return data
|
|
336
370
|
|
|
@@ -341,11 +375,13 @@ mockGetData('/relative-url', myMockObj);
|
|
|
341
375
|
or you can customize the response
|
|
342
376
|
|
|
343
377
|
```ts
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
HttpResponse.json({ foo: '
|
|
378
|
+
import { HttpResponse } from 'msw/http';
|
|
379
|
+
|
|
380
|
+
mockGetEndpoint('/relative-url', ({ request }) => {
|
|
381
|
+
if (new URL(request.url).searchParams.has('alternate')) {
|
|
382
|
+
return HttpResponse.json({ foo: 'bar' });
|
|
349
383
|
}
|
|
384
|
+
|
|
385
|
+
return HttpResponse.json({ foo: 'baz' });
|
|
350
386
|
});
|
|
351
387
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { http, HttpResponse } from 'msw/http';
|
|
2
|
+
import { setupServer } from 'msw/node';
|
|
3
|
+
import { expectTypeOf } from 'vitest';
|
|
4
|
+
import { createMockApiUtils, mockEndpoints } from '../../index.js';
|
|
5
|
+
const nativeFetch = globalThis.fetch;
|
|
6
|
+
const url = new URL('/api/items', window.location.href).href;
|
|
7
|
+
const server = setupServer(http.get(url, () => HttpResponse.json({ source: 'initial' })));
|
|
8
|
+
const utils = createMockApiUtils(server);
|
|
9
|
+
const verbs = ['get', 'post', 'put', 'delete', 'patch'];
|
|
10
|
+
const methods = [
|
|
11
|
+
'get',
|
|
12
|
+
'post',
|
|
13
|
+
'put',
|
|
14
|
+
'delete',
|
|
15
|
+
'patch',
|
|
16
|
+
'head',
|
|
17
|
+
'options',
|
|
18
|
+
'all',
|
|
19
|
+
];
|
|
20
|
+
const dataHelpers = {
|
|
21
|
+
get: utils.mockGetData,
|
|
22
|
+
post: utils.mockPostData,
|
|
23
|
+
put: utils.mockPutData,
|
|
24
|
+
delete: utils.mockDeleteData,
|
|
25
|
+
patch: utils.mockPatchData,
|
|
26
|
+
};
|
|
27
|
+
const endpointHelpers = {
|
|
28
|
+
get: utils.mockGetEndpoint,
|
|
29
|
+
post: utils.mockPostEndpoint,
|
|
30
|
+
put: utils.mockPutEndpoint,
|
|
31
|
+
delete: utils.mockDeleteEndpoint,
|
|
32
|
+
patch: utils.mockPatchEndpoint,
|
|
33
|
+
};
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
// setup-env stubs fetch before each test; let MSW intercept the native implementation instead.
|
|
36
|
+
vi.stubGlobal('fetch', nativeFetch);
|
|
37
|
+
server.listen({ onUnhandledFrame: 'error' });
|
|
38
|
+
});
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
server.resetHandlers();
|
|
41
|
+
server.close();
|
|
42
|
+
});
|
|
43
|
+
it('preserves the mockEndpoints compatibility export', () => {
|
|
44
|
+
expect(mockEndpoints).toBe(createMockApiUtils);
|
|
45
|
+
});
|
|
46
|
+
it.each(methods)('registers a %s data handler', async (method) => {
|
|
47
|
+
const data = { id: 1, name: 'Item' };
|
|
48
|
+
utils.mockEndpointData(url, data, method);
|
|
49
|
+
const response = await fetch(url, { method: method === 'all' ? 'POST' : method.toUpperCase() });
|
|
50
|
+
expect(response.status).toBe(200);
|
|
51
|
+
expect(response.headers.get('content-type')).toBe('application/json');
|
|
52
|
+
if (method === 'head') {
|
|
53
|
+
expect(await response.text()).toBe('');
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
expect(await response.json()).toEqual(data);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
it.each(methods)('registers a %s resolver handler', async (method) => {
|
|
60
|
+
utils.mockEndpoint(url, () => new HttpResponse(null, { status: 204, headers: { 'x-mocked': method } }), method);
|
|
61
|
+
const response = await fetch(url, { method: method === 'all' ? 'POST' : method.toUpperCase() });
|
|
62
|
+
expect(response.status).toBe(204);
|
|
63
|
+
expect(response.headers.get('x-mocked')).toBe(method);
|
|
64
|
+
expect(await response.text()).toBe('');
|
|
65
|
+
});
|
|
66
|
+
it.each(verbs)('returns JSON through the %s data helper', async (method) => {
|
|
67
|
+
const data = [{ id: 1 }, { id: 2 }];
|
|
68
|
+
dataHelpers[method]('/api/items', data);
|
|
69
|
+
const response = await fetch(url, { method: method.toUpperCase() });
|
|
70
|
+
expect(response.status).toBe(200);
|
|
71
|
+
expect(await response.json()).toEqual(data);
|
|
72
|
+
});
|
|
73
|
+
it.each(verbs)('supports asynchronous responses through the %s endpoint helper', async (method) => {
|
|
74
|
+
endpointHelpers[method]('/api/items/:id', async ({ request, params }) => {
|
|
75
|
+
const data = method === 'get' ? undefined : await request.json();
|
|
76
|
+
return HttpResponse.json({ id: params.id, method: request.method, data, query: new URL(request.url).searchParams.get('q') }, { status: 201 });
|
|
77
|
+
});
|
|
78
|
+
const data = { name: 'Updated item' };
|
|
79
|
+
const response = await fetch(`${url}/42?q=search`, {
|
|
80
|
+
method: method.toUpperCase(),
|
|
81
|
+
...(method !== 'get' && { body: JSON.stringify(data), headers: { 'content-type': 'application/json' } }),
|
|
82
|
+
});
|
|
83
|
+
expect(response.status).toBe(201);
|
|
84
|
+
expect(await response.json()).toEqual({
|
|
85
|
+
id: '42',
|
|
86
|
+
method: method.toUpperCase(),
|
|
87
|
+
...(method !== 'get' && { data }),
|
|
88
|
+
query: 'search',
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
it.each(verbs)('forwards once through the %s data helper', async (method) => {
|
|
92
|
+
dataHelpers[method](url, { source: 'fallback' });
|
|
93
|
+
dataHelpers[method](url, { source: 'once' }, { once: true });
|
|
94
|
+
const first = await fetch(url, { method: method.toUpperCase() });
|
|
95
|
+
const second = await fetch(url, { method: method.toUpperCase() });
|
|
96
|
+
expect(await first.json()).toEqual({ source: 'once' });
|
|
97
|
+
expect(await second.json()).toEqual({ source: 'fallback' });
|
|
98
|
+
});
|
|
99
|
+
it.each(verbs)('forwards once through the %s endpoint helper', async (method) => {
|
|
100
|
+
endpointHelpers[method](url, () => HttpResponse.json({ source: 'fallback' }));
|
|
101
|
+
endpointHelpers[method](url, () => HttpResponse.json({ source: 'once' }), { once: true });
|
|
102
|
+
const first = await fetch(url, { method: method.toUpperCase() });
|
|
103
|
+
const second = await fetch(url, { method: method.toUpperCase() });
|
|
104
|
+
expect(await first.json()).toEqual({ source: 'once' });
|
|
105
|
+
expect(await second.json()).toEqual({ source: 'fallback' });
|
|
106
|
+
});
|
|
107
|
+
it('resets runtime overrides to the initial server handlers', async () => {
|
|
108
|
+
utils.mockGetData(url, { source: 'override' });
|
|
109
|
+
const overridden = await fetch(url);
|
|
110
|
+
expect(await overridden.json()).toEqual({ source: 'override' });
|
|
111
|
+
server.resetHandlers();
|
|
112
|
+
const reset = await fetch(url);
|
|
113
|
+
expect(await reset.json()).toEqual({ source: 'initial' });
|
|
114
|
+
});
|
|
115
|
+
it.each([{ data: null }, { data: false }, { data: 0 }, { data: 'text' }, { data: [1, 2] }])('serializes JSON data $data without changing its value', async ({ data }) => {
|
|
116
|
+
utils.mockGetData(url, data);
|
|
117
|
+
const response = await fetch(url);
|
|
118
|
+
expect(await response.json()).toEqual(data);
|
|
119
|
+
});
|
|
120
|
+
it('allows an empty response body', async () => {
|
|
121
|
+
utils.mockGetData(url, undefined);
|
|
122
|
+
const response = await fetch(url);
|
|
123
|
+
expect(response.status).toBe(200);
|
|
124
|
+
expect(await response.text()).toBe('');
|
|
125
|
+
});
|
|
126
|
+
it('preserves typed path parameters, request bodies and response bodies', async () => {
|
|
127
|
+
utils.mockPostEndpoint(`${url}/:id`, async ({ request, params }) => {
|
|
128
|
+
const body = await request.json();
|
|
129
|
+
expectTypeOf(params).toEqualTypeOf();
|
|
130
|
+
expectTypeOf(body).toEqualTypeOf();
|
|
131
|
+
return HttpResponse.json({ id: params.id, name: body.name });
|
|
132
|
+
});
|
|
133
|
+
const response = await fetch(`${url}/42`, {
|
|
134
|
+
method: 'POST',
|
|
135
|
+
body: JSON.stringify({ name: 'Typed item' }),
|
|
136
|
+
headers: { 'content-type': 'application/json' },
|
|
137
|
+
});
|
|
138
|
+
expect(response.status).toBe(200);
|
|
139
|
+
expect(await response.json()).toEqual({ id: '42', name: 'Typed item' });
|
|
140
|
+
});
|
|
141
|
+
//# sourceMappingURL=mockEndpoints.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockEndpoints.spec.js","sourceRoot":"src/","sources":["utils/__tests__/mockEndpoints.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,aAAa,E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AY,CAAC,IAAI,CAAe,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,KAAK,EAAE;QACxC,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;QAC5C,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;KAChD,CAAC,CAAC;IAEH,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,MAAM,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { type DefaultBodyType,
|
|
2
|
-
import {
|
|
1
|
+
import { type DefaultBodyType, type PathParams, type RequestHandlerOptions } from 'msw';
|
|
2
|
+
import { http, type HttpResponseResolver } from 'msw/http';
|
|
3
|
+
import { type SetupServer } from 'msw/node';
|
|
3
4
|
export type RestMethod = keyof typeof http;
|
|
4
5
|
export default function createMockApiUtils(server: SetupServer): {
|
|
5
6
|
mockEndpointData: <ResponseBody extends DefaultBodyType = undefined>(url: string, responseData: ResponseBody, method: RestMethod, options?: RequestHandlerOptions) => void;
|
|
6
|
-
mockEndpoint: <Params extends PathParams<keyof Params> = PathParams, RequestBodyType extends DefaultBodyType = DefaultBodyType, ResponseBodyType extends DefaultBodyType = undefined>(relativeUrl: string, resolver:
|
|
7
|
-
mockGetData: (url: string, responseData:
|
|
8
|
-
mockPostData: (url: string, responseData:
|
|
9
|
-
mockPutData: (url: string, responseData:
|
|
10
|
-
mockDeleteData: (url: string, responseData:
|
|
11
|
-
mockPatchData: (url: string, responseData:
|
|
12
|
-
mockGetEndpoint: (url: string, resolver:
|
|
13
|
-
mockPostEndpoint: (url: string, resolver:
|
|
14
|
-
mockPutEndpoint: (url: string, resolver:
|
|
15
|
-
mockDeleteEndpoint: (url: string, resolver:
|
|
16
|
-
mockPatchEndpoint: (url: string, resolver:
|
|
7
|
+
mockEndpoint: <Params extends PathParams<keyof Params> = PathParams, RequestBodyType extends DefaultBodyType = DefaultBodyType, ResponseBodyType extends DefaultBodyType = undefined>(relativeUrl: string, resolver: HttpResponseResolver<Params, RequestBodyType, ResponseBodyType>, method: RestMethod, options?: RequestHandlerOptions) => void;
|
|
8
|
+
mockGetData: <ResponseBody extends DefaultBodyType = undefined>(url: string, responseData: ResponseBody, options?: RequestHandlerOptions) => void;
|
|
9
|
+
mockPostData: <ResponseBody extends DefaultBodyType = undefined>(url: string, responseData: ResponseBody, options?: RequestHandlerOptions) => void;
|
|
10
|
+
mockPutData: <ResponseBody extends DefaultBodyType = undefined>(url: string, responseData: ResponseBody, options?: RequestHandlerOptions) => void;
|
|
11
|
+
mockDeleteData: <ResponseBody extends DefaultBodyType = undefined>(url: string, responseData: ResponseBody, options?: RequestHandlerOptions) => void;
|
|
12
|
+
mockPatchData: <ResponseBody extends DefaultBodyType = undefined>(url: string, responseData: ResponseBody, options?: RequestHandlerOptions) => void;
|
|
13
|
+
mockGetEndpoint: <Params extends PathParams<keyof Params> = PathParams, RequestBodyType extends DefaultBodyType = DefaultBodyType, ResponseBodyType extends DefaultBodyType = undefined>(url: string, resolver: HttpResponseResolver<Params, RequestBodyType, ResponseBodyType>, options?: RequestHandlerOptions) => void;
|
|
14
|
+
mockPostEndpoint: <Params extends PathParams<keyof Params> = PathParams, RequestBodyType extends DefaultBodyType = DefaultBodyType, ResponseBodyType extends DefaultBodyType = undefined>(url: string, resolver: HttpResponseResolver<Params, RequestBodyType, ResponseBodyType>, options?: RequestHandlerOptions) => void;
|
|
15
|
+
mockPutEndpoint: <Params extends PathParams<keyof Params> = PathParams, RequestBodyType extends DefaultBodyType = DefaultBodyType, ResponseBodyType extends DefaultBodyType = undefined>(url: string, resolver: HttpResponseResolver<Params, RequestBodyType, ResponseBodyType>, options?: RequestHandlerOptions) => void;
|
|
16
|
+
mockDeleteEndpoint: <Params extends PathParams<keyof Params> = PathParams, RequestBodyType extends DefaultBodyType = DefaultBodyType, ResponseBodyType extends DefaultBodyType = undefined>(url: string, resolver: HttpResponseResolver<Params, RequestBodyType, ResponseBodyType>, options?: RequestHandlerOptions) => void;
|
|
17
|
+
mockPatchEndpoint: <Params extends PathParams<keyof Params> = PathParams, RequestBodyType extends DefaultBodyType = DefaultBodyType, ResponseBodyType extends DefaultBodyType = undefined>(url: string, resolver: HttpResponseResolver<Params, RequestBodyType, ResponseBodyType>, options?: RequestHandlerOptions) => void;
|
|
17
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockEndpoints.js","sourceRoot":"src/","sources":["utils/mockEndpoints.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mockEndpoints.js","sourceRoot":"src/","sources":["utils/mockEndpoints.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,YAAY,EAA6B,MAAM,UAAU,CAAC;AAKzE,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,MAAmB;IAC5D;;OAEG;IACH,MAAM,gBAAgB,GAAG,CACvB,GAAW,EACX,YAA0B,EAC1B,MAAkB,EAClB,OAA+B,EAC/B,EAAE;QACF,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAChF,CAAC,CAAC;IAEF;;OAEG;IACH,MAAM,YAAY,GAAG,CAKnB,WAAmB,EACnB,QAAyE,EACzE,MAAkB,EAClB,OAA+B,EAC/B,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": "0.0.0-PR-313--bdb408d",
|
|
4
4
|
"description": "Frontend DOM testing utilities",
|
|
5
5
|
"packageManager": "pnpm@12.6.0",
|
|
6
6
|
"engines": {
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"msw": "^3.0.
|
|
44
|
+
"msw": "^3.0.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@leaflink/eslint-config": "^5.3.0",
|
|
48
48
|
"@types/node": "^25.9.0",
|
|
49
49
|
"@vitest/coverage-v8": "^5.0.0",
|
|
50
50
|
"commitlint": "^21.0.0",
|
|
51
|
-
"conventional-changelog-conventionalcommits": "^
|
|
51
|
+
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
52
52
|
"eslint": "^10.0.0",
|
|
53
53
|
"jsdom": "^30.0.0",
|
|
54
54
|
"semantic-release": "^25.0.3",
|