Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 91d19ff

Browse files
committed
Update mws dependency
Signed-off-by: Michael Weimann <[email protected]>
1 parent 79e4437 commit 91d19ff

File tree

5 files changed

+246
-346
lines changed

5 files changed

+246
-346
lines changed

packages/element-web-guest-module/jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,10 @@ module.exports = {
2121
roots: ['<rootDir>/src'],
2222
preset: 'ts-jest',
2323
testEnvironment: 'jsdom',
24+
// Fix imports not found
25+
// https://mswjs.io/docs/migrations/1.x-to-2.x#cannot-find-module-mswnode-jsdom
26+
testEnvironmentOptions: {
27+
customExportConditions: [''],
28+
},
2429
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
2530
};

packages/element-web-guest-module/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@types/react": "^17",
2929
"cross-fetch": "^4.0.0",
3030
"esbuild": "^0.20.2",
31-
"msw": "^1.3.2",
31+
"msw": "^2.4.11",
3232
"react": "17.0.2",
3333
"react-dom": "17.0.2",
3434
"typescript": "~5.0.4"

packages/element-web-guest-module/src/components/RegisterDialog.test.tsx

+12-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { ModuleApi } from '@matrix-org/react-sdk-module-api/lib/ModuleApi';
1818
import { AccountAuthInfo } from '@matrix-org/react-sdk-module-api/lib/types/AccountAuthInfo';
1919
import { render, screen, waitFor } from '@testing-library/react';
2020
import userEvent from '@testing-library/user-event';
21-
import { rest } from 'msw';
21+
import { HttpResponse, http } from 'msw';
2222
import { setupServer } from 'msw/node';
2323
import React from 'react';
2424
import { generatePassword } from '../utils';
@@ -75,20 +75,24 @@ describe('<RegisterDialog />', () => {
7575
await userEvent.type(nameInput, 'My Name');
7676

7777
let resolvePromise: (value: AccountAuthInfo) => void | undefined;
78+
7879
server.use(
79-
rest.post(
80+
http.post(
8081
'http://synapse.local/_synapse/client/register_guest',
81-
async (req, res, ctx) => {
82-
const body = await req.json();
82+
async ({ request }) => {
83+
const body = (await request.json()) as { displayname: string };
84+
8385
if (body.displayname !== 'My Name') {
84-
return res(ctx.status(400));
86+
return new HttpResponse(null, {
87+
status: 400,
88+
});
8589
}
8690

8791
const response = await new Promise<AccountAuthInfo>((resolve) => {
8892
resolvePromise = resolve;
8993
});
9094

91-
return res(ctx.json(response));
95+
return HttpResponse.json(response);
9296
},
9397
),
9498
);
@@ -190,9 +194,9 @@ describe('<RegisterDialog />', () => {
190194
await userEvent.type(nameInput, 'My Name');
191195

192196
server.use(
193-
rest.post(
197+
http.post(
194198
'http://synapse.local/_synapse/client/register_guest',
195-
async (_, res, ctx) => res(ctx.status(400)),
199+
async () => new Response(undefined, { status: 400 }),
196200
),
197201
);
198202

packages/element-web-guest-module/src/setupTests.ts

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { TextDecoder, TextEncoder } from 'util';
18+
1719
// jest-dom adds custom jest matchers for asserting on DOM nodes.
1820
// allows you to do things like:
1921
// expect(element).toHaveTextContent(/react/i)
@@ -23,3 +25,6 @@ import '@testing-library/jest-dom';
2325
// Jest don't support the native node-fetch in the jsdom environment yet
2426
// https://github.com/jsdom/jsdom/issues/1724
2527
import 'cross-fetch/polyfill';
28+
29+
// Publish TextEncoder and TextDecoder in the global scope
30+
Object.assign(global, { TextDecoder, TextEncoder });

0 commit comments

Comments
 (0)