| 1 |
import { Server } from "miragejs"; |
| 2 |
|
| 3 |
describe("External | Shared | Server | loadFixtures", () => { |
| 4 |
let server; |
| 5 |
beforeEach(() => { |
| 6 |
server = new Server({ |
| 7 |
environment: "test", |
| 8 |
factories: { |
| 9 |
author: {}, |
| 10 |
post: {}, |
| 11 |
comment: {}, |
| 12 |
}, |
| 13 |
fixtures: { |
| 14 |
authors: [ |
| 15 |
{ id: 1, name: "Zelda" }, |
| 16 |
{ id: 2, name: "Link" }, |
| 17 |
], |
| 18 |
posts: [ |
| 19 |
{ id: 1, title: "Lorem" }, |
| 20 |
{ id: 2, title: "Ipsum" }, |
| 21 |
], |
| 22 |
comments: [{ id: 1, title: "Lorem" }], |
| 23 |
}, |
| 24 |
}); |
| 25 |
}); |
| 26 |
|
| 27 |
afterEach(function () { |
| 28 |
server.shutdown(); |
| 29 |
}); |
| 30 |
|
| 31 |
test("it can load all fixtures in the map", () => { |
| 32 |
server.loadFixtures(); |
| 33 |
|
| 34 |
expect(server.db.authors).toHaveLength(2); |
| 35 |
expect(server.db.posts).toHaveLength(2); |
| 36 |
expect(server.db.comments).toHaveLength(1); |
| 37 |
}); |
| 38 |
|
| 39 |
test("it can load a single named fixture file", () => { |
| 40 |
server.loadFixtures("authors"); |
| 41 |
|
| 42 |
expect(server.db.authors).toHaveLength(2); |
| 43 |
expect(server.db.posts).toHaveLength(0); |
| 44 |
expect(server.db.comments).toHaveLength(0); |
| 45 |
}); |
| 46 |
|
| 47 |
test("it can load several named single fixtures", () => { |
| 48 |
server.loadFixtures("authors", "posts"); |
| 49 |
|
| 50 |
expect(server.db.authors).toHaveLength(2); |
| 51 |
expect(server.db.posts).toHaveLength(2); |
| 52 |
expect(server.db.comments).toHaveLength(0); |
| 53 |
}); |
| 54 |
|
| 55 |
test("it throws on a non-existing file name", () => { |
| 56 |
expect(() => |
| 57 |
server.loadFixtures("authors", "zomg", "posts", "lol") |
| 58 |
).toThrow("Fixtures not found: zomg, lol"); |
| 59 |
}); |
| 60 |
}); |