Debian Codegraph @

__tests__/external/shared/orm/has-many/3-reflexive/association-new-test.js

raw
1 import Helper, { states } from "./_helper";
2
3 describe("External | Shared | ORM | Has Many | Reflexive | association #new", () => {
4 let helper;
5 beforeEach(() => {
6 helper = new Helper();
7 });
8 afterEach(() => {
9 helper.shutdown();
10 });
11
12 /*
13 The model can make a new unsaved belongs-to association, for all states
14 */
15
16 states.forEach((state) => {
17 test(`a ${state} can build a new associated child`, () => {
18 let [tag] = helper[state]();
19 let initialCount = tag.tags.models.length;
20
21 let blueTag = tag.newTag({ name: "Blue" });
22
23 expect(!blueTag.id).toBeTruthy();
24 expect(tag.tags.models).toHaveLength(initialCount + 1);
25 expect(blueTag.tags.models).toHaveLength(1);
26
27 blueTag.save();
28 tag.reload();
29
30 expect(blueTag.attrs).toEqual({
31 id: blueTag.id,
32 name: "Blue",
33 tagIds: [tag.id],
34 });
35 expect(tag.tags.models).toHaveLength(initialCount + 1);
36 expect(tag.tags.includes(blueTag)).toBeTruthy();
37 expect(tag.tagIds.indexOf(blueTag.id) > -1).toBeTruthy();
38 expect(blueTag.tags.includes(tag)).toBeTruthy();
39 });
40 });
41 });