Skip to content

Commit 1a09d82

Browse files
committed
ci: add test case for circular referencing issue
1 parent 5859496 commit 1a09d82

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

src/generators/__snapshots__/class.spec.ts.snap

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,57 @@ type 'MockedClass'.
8282
| Description | test |
8383
8484
85+
"
86+
`;
87+
88+
exports[`generateDocsForClass() Function should not generate documentation for circular references 1`] = `
89+
"# Type \`MockedClass\`
90+
91+
test
92+
93+
## Fields
94+
95+
- [test](#test)
96+
97+
98+
### \`test\`
99+
100+
| Name | Description |
101+
| ----------- | ------------------------------ |
102+
| Type | [ChildClass](#type-childclass) |
103+
| Nullable | ❌ No |
104+
| Description | test |
105+
106+
107+
108+
## Type \`ChildClass\`
109+
110+
test
111+
112+
### Fields
113+
114+
- [childField](#childfield)
115+
- [field](#field)
116+
117+
118+
#### \`childField\`
119+
120+
| Name | Description |
121+
| ----------- | ---------------------- |
122+
| Type | String |
123+
| Nullable | ❌ No |
124+
| Description | This is a child field. |
125+
126+
127+
128+
#### \`field\`
129+
130+
| Name | Description |
131+
| ----------- | ------------------------------ |
132+
| Type | [ChildClass](#type-childclass) |
133+
| Nullable | ❌ No |
134+
| Description | test |
135+
136+
85137
"
86138
`;

src/generators/class.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "reflect-metadata";
22

33
import { generateForClass } from "@generators/class";
44
import { DocField } from "@decorators/field";
5+
import { DocType } from "@root/decorators";
56

67
describe("generateDocsForClass() Function", function () {
78
it("should be defined", function () {
@@ -62,6 +63,41 @@ describe("generateDocsForClass() Function", function () {
6263
expect(generatedData).toMatchSnapshot();
6364
});
6465

66+
it("should not generate documentation for circular references", function () {
67+
@DocType({
68+
description: "test",
69+
})
70+
class ChildClass {
71+
@DocField({
72+
description: "This is a child field.",
73+
})
74+
public childField!: string;
75+
76+
@DocField({
77+
description: "test",
78+
nullable: false,
79+
})
80+
public field!: ChildClass;
81+
}
82+
83+
@DocType({
84+
description: "test",
85+
})
86+
class MockedClass {
87+
@DocField({
88+
description: "test",
89+
nullable: false,
90+
})
91+
public test!: ChildClass;
92+
}
93+
94+
const generatedData = generateForClass(MockedClass, {
95+
combineNestedFields: true,
96+
});
97+
98+
expect(generatedData).toMatchSnapshot();
99+
});
100+
65101
it("should throw an error if the class is not registered", function () {
66102
expect(() => {
67103
generateForClass(String);

0 commit comments

Comments
 (0)