I am using https://www.npmjs.com/package/axios-mock-adapter to fetch mock response .but I am not able to get mock response.
here is my code https://codesandbox.io/s/frosty-surf-g9tezx?file=/src/App.js
here I am fetching actual data
React.useEffect(() => {
const a = async function () {
const ab = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
console.log(ab);
};
a();
}, []);
using axios adaptor I mock API
// This sets the mock adapter on the default instance
var mock = new MockAdapter(axios);
// Mock any GET request to /users
// arguments for reply are (status, data, headers)
mock.onGet("https://jsonplaceholder.typicode.com/todos/1").reply(200, {
users: [{ id: 1, name: "John Smith" }],
});
I need instead of actual request it will get mock response or in other words I can toggle my option sometimes it goes to actual request or some time it goes from mock api