Skip to content

Commit

Permalink
modif modal use axios-mock-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Khagou committed Mar 23, 2024
1 parent 59624fc commit b94e9dc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
29 changes: 15 additions & 14 deletions client/__tests__/Modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ import {
waitFor
} from "@testing-library/react";
import PortfolioContent from "../src/components/Portfolio/PortfolioContent.js";
import fetchMock from "jest-fetch-mock";
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import "@testing-library/jest-dom";

fetchMock.enableMocks();
// This sets the mock adapter on the default instance
var mock = new MockAdapter(axios);

beforeEach(() => {
fetch.resetMocks();
fetch.mockResponseOnce(
JSON.stringify([
{
_id: "63010eb139a57ed333541505",
name: "adposeAccueil",
chemin: "./images/adpose.PNG",
__v: 0,
caption: "caption",
},
])
);
// Mock any GET request to /images
// arguments for reply are (status, data, headers)
mock.onGet(process.env.REACT_APP_URL_API + "/images").reply(200, [
{
_id: "63010eb139a57ed333541505",
name: "adposeAccueil",
chemin: "./images/adpose.PNG",
__v: 0,
caption: "caption",
},
]);
});

beforeEach(() => {
Expand Down
37 changes: 37 additions & 0 deletions client/package-lock.json

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

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@babel/preset-react": "^7.23.3",
"@testing-library/jest-dom": "^6.3.0",
"@testing-library/react": "^14.1.2",
"axios-mock-adapter": "^1.22.0",
"babel-jest": "^29.7.0",
"eslint": "^8.56.0",
"eslint-config-google": "^0.14.0",
Expand Down

0 comments on commit b94e9dc

Please sign in to comment.