Skip to content

Commit

Permalink
Merge pull request #99 from ligangty/2.0-refactor
Browse files Browse the repository at this point in the history
Use fetch-mock instead of jest-fetch-mock
  • Loading branch information
ligangty authored Nov 24, 2023
2 parents 96a9ac7 + 4b99cee commit 9c7aa3b
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 41 deletions.
158 changes: 127 additions & 31 deletions src/main/webui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/main/webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"verbose": true,
"automock": false,
"resetMocks": false,
"setupFiles": ["<rootDir>/setupTests.js"]
"setupFiles": [
"<rootDir>/setupTests.js"
]
},
"dependencies": {
"bootstrap": "^5.3.2",
Expand Down Expand Up @@ -45,9 +47,9 @@
"eslint-plugin-react": "^7.33.2",
"eslint-webpack-plugin": "^4.0.1",
"express": "^4.18.2",
"fetch-mock": "^9.11.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"nodemon": "^3.0.1",
"style-loader": "^3.3.3",
"url-loader": "^4.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/main/webui/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import fetchMock, {FetchMock as fetch} from "jest-fetch-mock";
import fetchMock from "fetch-mock";

fetchMock.enableMocks();
fetchMock.restore();
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

import React from "react";
import {render, screen, cleanup, waitFor} from '@testing-library/react';
import fetchMock from "jest-fetch-mock";
import fetchMock from "fetch-mock";
import userEvent from "@testing-library/user-event";
import '@testing-library/jest-dom';
import {PackageTypeSelect} from "./PackageTypeSelect.jsx";

beforeEach(() => {
fetchMock.resetMocks();
fetchMock.mockResponseOnce(JSON.stringify(["maven", "npm", "generic-http"]));
fetchMock.restore();
fetchMock.mock(
"/api/stats/package-type/keys",
{status: 200, body: JSON.stringify(["maven", "npm", "generic-http"])}
);
});

afterEach(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/main/webui/src/app/components/nav/NavFooter.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import React from "react";
import {render, screen, cleanup, waitFor} from '@testing-library/react';
import '@testing-library/jest-dom';
import fetchMock from "jest-fetch-mock";
import fetchMock from "fetch-mock";
import NavFooter from "./NavFooter.jsx";

beforeEach(() => {
fetchMock.resetMocks();
fetchMock.restore();
});

afterEach(() => {
Expand All @@ -36,7 +36,7 @@ describe('Footer tests', () => {
builder: "test-builder",
timestamp: "2023-10-24 05:54 +0000"
};
fetchMock.mockResponseOnce(JSON.stringify(mockStats));
fetchMock.mock("/api/stats/version-info", {status: 200, body: JSON.stringify(mockStats)});

render(<NavFooter />);
expect(screen.getByRole("link", {name: "Docs"})).toHaveAttribute("href", "http://commonjava.github.io/indy/");
Expand Down

0 comments on commit 9c7aa3b

Please sign in to comment.