-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmsw.test.ts
More file actions
25 lines (21 loc) · 740 Bytes
/
msw.test.ts
File metadata and controls
25 lines (21 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";
import { expect } from "$fresh-testing-library/expect.ts";
import { afterAll, beforeAll, describe, it } from "$std/testing/bdd.ts";
// You should pass `--location` flag.
expect(location).toBeTruthy();
describe("msw", () => {
const server = setupServer(
http.get(`${location.origin}/api/user`, () =>
HttpResponse.json({
id: 1,
name: "foo",
})),
);
beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
afterAll(() => server.close());
it("can be used to intercept requests", async () => {
const res = await fetch("/api/user");
expect(await res.json()).toEqual({ id: 1, name: "foo" });
});
});