Skip to content

Commit fdb2e6d

Browse files
committed
AKR:OTR:VKT:YKI:SHARED(Frontend) OPHAKRKEH-515 jest migration test fixes
1 parent bade99e commit fdb2e6d

File tree

20 files changed

+610
-251
lines changed

20 files changed

+610
-251
lines changed

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@
9090
"git-revision-webpack-plugin": "^5.0.0",
9191
"html-webpack-plugin": "^5.5.3",
9292
"jest": "^29.7.0",
93+
"jest-environment-jsdom": "^29.7.0",
9394
"mini-css-extract-plugin": "^2.7.6",
94-
"msw": "^2.0.3",
95+
"msw": "^2.0.4",
9596
"postcss": "^8.4.31",
9697
"prettier": "^3.0.3",
9798
"react-test-renderer": "^18.2.0",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// test.environment.js
2+
3+
const JSDOMEnvironment = require("jest-environment-jsdom").default;
4+
5+
module.exports = class CustomTestEnvironment extends JSDOMEnvironment {
6+
async setup() {
7+
await super.setup();
8+
this.global.TextEncoder = TextEncoder;
9+
this.global.TextDecoder = TextDecoder;
10+
this.global.Response = Response;
11+
this.global.Request = Request;
12+
}
13+
};

frontend/packages/akr/jest.config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
"setupFilesAfterEnv": [
1515
"./jest-setup.ts"
1616
],
17-
"testEnvironment": "jsdom",
17+
"testEnvironment": "./jest-environment-patched-jsdom.js",
1818
"testPathIgnorePatterns": [
1919
"./src/tests/cypress"
2020
],
21+
"testEnvironmentOptions": {
22+
"customExportConditions": [""]
23+
},
2124
"transform": {
2225
"^.+\\.(ts|tsx)$": "babel-jest"
2326
},

frontend/packages/akr/src/tests/jest/components/layouts/__snapshots__/Header.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Header should render Header correctly 1`] = `
4-
Array [
4+
[
55
<a
6-
className="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways skip-link css-tvmhkj-MuiTypography-root-MuiLink-root"
6+
className="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways skip-link css-1vrl3mg-MuiTypography-root-MuiLink-root"
77
href="#main-content"
88
onBlur={[Function]}
99
onFocus={[Function]}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// test.environment.js
2+
3+
const JSDOMEnvironment = require("jest-environment-jsdom").default;
4+
5+
module.exports = class CustomTestEnvironment extends JSDOMEnvironment {
6+
async setup() {
7+
await super.setup();
8+
this.global.TextEncoder = TextEncoder;
9+
this.global.TextDecoder = TextDecoder;
10+
this.global.Response = Response;
11+
this.global.Request = Request;
12+
}
13+
};

frontend/packages/otr/jest.config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
"setupFilesAfterEnv": [
1616
"./jest-setup.ts"
1717
],
18-
"testEnvironment": "jsdom",
18+
"testEnvironment": "./jest-environment-patched-jsdom.js",
1919
"testPathIgnorePatterns": [
2020
"./src/tests/cypress"
2121
],
22+
"testEnvironmentOptions": {
23+
"customExportConditions": [""]
24+
},
2225
"testTimeout": 10000,
2326
"transform": {
2427
"^.+\\.(ts|tsx)$": "babel-jest"

frontend/packages/otr/src/tests/jest/pages/PublicHomePage.test.tsx

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { screen } from '@testing-library/dom';
2-
import { act } from '@testing-library/react';
2+
import { waitFor } from '@testing-library/react';
33
import { userEvent } from '@testing-library/user-event';
44

55
import { PublicHomePage } from 'pages/PublicHomePage';
@@ -8,9 +8,9 @@ import { publicInterpreters10 } from 'tests/msw/fixtures/publicInterpreters10';
88

99
describe('PublicHomePage', () => {
1010
it('should show number of loaded interpreters in the search button', async () => {
11-
await act(async () => {
12-
render(<PublicHomePage />);
13-
});
11+
await waitFor(() =>
12+
render(<PublicHomePage />)
13+
);
1414
const searchBtnEl = await screen.findByRole('button', {
1515
name: `buttons.search (${publicInterpreters10.length})`,
1616
});
@@ -19,53 +19,52 @@ describe('PublicHomePage', () => {
1919
});
2020

2121
it('should filter data based on active filters', async () => {
22-
await act(async () => {
23-
render(<PublicHomePage />);
24-
});
22+
await waitFor(() =>
23+
render(<PublicHomePage />)
24+
);
2525

2626
// Check initial number of interpreters
2727
expect(
2828
await screen.findByTestId('public-interpreter-filters__search-btn'),
2929
).toHaveTextContent('10');
3030

31-
// Select to field
32-
await act(async () => {
33-
await userEvent.click(
34-
await screen.findByRole('combobox', {
31+
const comboBox = await screen.findByRole('combobox', {
3532
name: 'languagePair.toPlaceholder',
36-
}),
37-
);
38-
});
39-
await act(async () => {
40-
await userEvent.click(screen.getByRole('option', { name: /DA/ }));
33+
});
34+
// Select to field
35+
await waitFor(() =>
36+
userEvent.click(
37+
comboBox,
38+
)
39+
);
40+
const optionDA = await screen.getByRole('option', { name: /DA/ });
41+
await waitFor(() => {
42+
userEvent.click(optionDA)
4143
});
4244
expect(
4345
await screen.findByTestId('public-interpreter-filters__search-btn'),
4446
).toHaveTextContent('4');
4547

4648
// Select the region
47-
await act(async () => {
48-
await userEvent.click(
49+
await waitFor(() =>
50+
userEvent.click(
4951
screen.getByRole('combobox', {
5052
name: 'region.placeholder',
5153
}),
52-
);
53-
});
54-
await act(async () => {
55-
await userEvent.click(screen.getByRole('option', { name: /05/ }));
56-
});
54+
)
55+
);
56+
const option05 = await screen.getByRole('option', { name: /05/ });
57+
await waitFor(() =>
58+
userEvent.click(option05)
59+
);
5760
expect(
5861
await screen.findByTestId('public-interpreter-filters__search-btn'),
5962
).toHaveTextContent('3');
6063

64+
const input = await screen.getByLabelText('name.placeholder', { selector: 'input' });
6165
// Type the name
62-
await act(async () => {
63-
await userEvent.type(
64-
screen.getByLabelText('name.placeholder', { selector: 'input' }),
65-
'ville',
66-
{ delay: 300 },
67-
);
68-
});
66+
await userEvent.type(input, 'ville', { delay: 300 });
67+
6968
expect(
7069
await screen.findByTestId('public-interpreter-filters__search-btn'),
7170
).toHaveTextContent('2');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// test.environment.js
2+
3+
const JSDOMEnvironment = require("jest-environment-jsdom").default;
4+
5+
module.exports = class CustomTestEnvironment extends JSDOMEnvironment {
6+
async setup() {
7+
await super.setup();
8+
this.global.TextEncoder = TextEncoder;
9+
this.global.TextDecoder = TextDecoder;
10+
this.global.Response = Response;
11+
this.global.Request = Request;
12+
}
13+
};

frontend/packages/vkt/jest.config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
"setupFilesAfterEnv": [
1616
"./jest-setup.ts"
1717
],
18-
"testEnvironment": "jsdom",
18+
"testEnvironment": "./jest-environment-patched-jsdom.js",
1919
"testPathIgnorePatterns": [
2020
"./src/tests/cypress"
2121
],
22+
"testEnvironmentOptions": {
23+
"customExportConditions": [""]
24+
},
2225
"testTimeout": 10000,
2326
"transform": {
2427
"^.+\\.(ts|tsx)$": "babel-jest"

frontend/packages/vkt/src/tests/jest/components/layouts/__snapshots__/Header.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Header should render Header correctly 1`] = `
4-
Array [
4+
[
55
<a
6-
className="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways skip-link css-tvmhkj-MuiTypography-root-MuiLink-root"
6+
className="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineAlways skip-link css-1vrl3mg-MuiTypography-root-MuiLink-root"
77
href="#main-content"
88
onBlur={[Function]}
99
onFocus={[Function]}

0 commit comments

Comments
 (0)