Files
bun.sh/test/js/third_party/msw/msw.fixture.ts
2024-09-03 21:32:52 -07:00

27 lines
571 B
TypeScript

import axios from "axios";
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";
const server = setupServer(
...[
http.get("http://localhost/", () => {
// return passthrough()
return HttpResponse.json({ results: [{}, {}] });
}),
],
);
server.listen({
onUnhandledRequest: "warn",
});
axios
.get("http://localhost/?page=2")
.then(function (response) {
// handle success
console.log(response.data.results.length);
})
.catch(function (error) {
// handle error
console.log(error?.message);
});