Debian Codegraph @

__tests__/external/shared/server/seeds-test.js

raw
1 import { Server, Model } from "miragejs";
2
3 describe("External | Shared | Server | seeds", () => {
4 let server;
5
6 afterEach(function () {
7 server.shutdown();
8 });
9
10 test("seeds config option works", async () => {
11 server = new Server({
12 models: {
13 user: Model,
14 },
15 seeds(server) {
16 server.createList("user", 3);
17 },
18 });
19
20 expect(server.db.dump()).toEqual({
21 users: [{ id: "1" }, { id: "2" }, { id: "3" }],
22 });
23 });
24
25 test("there's an error if both scenarios default and seeds options are passed in", async () => {
26 expect(() => {
27 new Server({
28 environment: "test",
29 seeds(server) {
30 server.create("user");
31 },
32 scenarios: {
33 default(server) {
34 server.create("user");
35 },
36 },
37 });
38 }).toThrow(
39 "The seeds option is an alias for the scenarios.default option. You can't pass both options into your server definition."
40 );
41 });
42 });