Debian Codegraph @

__tests__/internal/move-after-handle-request/routes-test.js

raw
1 import { Server, Model } from "miragejs";
2
3 describe("Integration | Routes", () => {
4 let server;
5
6 afterEach(function () {
7 server.shutdown();
8 });
9
10 test("routes config option works", async () => {
11 server = new Server({
12 environment: "test",
13 models: {
14 user: Model,
15 },
16 routes() {
17 this.namespace = "api";
18
19 this.get("/users");
20 },
21 });
22
23 server.createList("user", 3);
24
25 let data = await fetch("/api/users").then((res) => res.json());
26
27 expect(data).toEqual({
28 users: [{ id: "1" }, { id: "2" }, { id: "3" }],
29 });
30 });
31
32 test("there's an error if both baseConfig and routes options are passed in", async () => {
33 expect(() => {
34 new Server({
35 environment: "test",
36 routes() {
37 this.get("/users", () => ({ users: [] }));
38 },
39 baseConfig() {
40 this.get("/posts", () => ({ posts: [] }));
41 },
42 });
43 }).toThrow(
44 "The routes option is an alias for the baseConfig option. You can't pass both options into your server definition."
45 );
46 });
47 });