Debian Codegraph @

__tests__/internal/unit/collection-test.js

raw
1 import Collection from "@lib/orm/collection";
2
3 describe("Unit | Collection", function () {
4 test("it can be instantiated", () => {
5 let collection = new Collection("plant");
6
7 expect(collection).toBeTruthy();
8 });
9
10 test("it cannot be instantiated without a modelName", () => {
11 expect(() => {
12 new Collection();
13 }).toThrow(/must pass a `modelName`/);
14 });
15
16 test("it knows its modelname", () => {
17 let collection = new Collection("author");
18
19 expect(collection.modelName).toEqual("author");
20 });
21
22 test("it can be instantiated with an array of models", () => {
23 let models = [{ id: 1 }, { id: 2 }, { id: 3 }];
24 let collection = new Collection("author", models);
25
26 expect(collection).toBeTruthy();
27 });
28
29 test("#models returns the underlying array", () => {
30 let models = [{ id: 1 }, { id: 2 }, { id: 3 }];
31 let collection = new Collection("author", models);
32
33 expect(collection.models).toEqual(models);
34 });
35
36 test("#length returns the number of elements", () => {
37 let models = [{ id: 1 }, { id: 2 }];
38 let collection = new Collection("post", models);
39
40 expect(collection).toHaveLength(2);
41
42 collection.models = [{ id: 1 }];
43 expect(collection).toHaveLength(1);
44 });
45 });