Skip to content

Commit 0115291

Browse files
committed
test(parser): expand coverage for complex destructuring and generic prefixes
1 parent 9d04e81 commit 0115291

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

src/generators/metadata/utils/__tests__/transformers.test.mjs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('transformTypeToReferenceLink', () => {
7979
it('should transform a function returning a Generic type', () => {
8080
strictEqual(
8181
transformTypeToReferenceLink('(err: Error) => Promise<boolean>', {}),
82-
'(err: Error) =&gt; [`<Promise>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[`<boolean>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#boolean_type)&gt;'
82+
'(err: [`<Error>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)) =&gt; [`<Promise>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[`<boolean>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#boolean_type)&gt;'
8383
);
8484
});
8585

@@ -90,12 +90,26 @@ describe('transformTypeToReferenceLink', () => {
9090
);
9191
});
9292

93-
it('should handle extreme nested combinations of functions, generics, unions, and intersections', () => {
93+
it('should handle extreme nested combinations of functions, arrays, generics, unions, and intersections', () => {
9494
const input =
95-
'(str: MyType) => Promise<Map<string, number & string>, Map<string | number>>';
95+
'(str: string[]) => Promise<Map<string, number & string>, Map<string | number>>';
96+
9697
const expected =
97-
'(str: MyType) =&gt; [`<Promise>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[`<Map>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)&lt;[`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type), [`<number>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type) & [`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type)&gt;, [`<Map>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)&lt;[`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type) | [`<number>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type)&gt;&gt;';
98+
'(str: [`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type)[]) =&gt; [`<Promise>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[`<Map>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)&lt;[`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type), [`<number>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type) & [`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type)&gt;, [`<Map>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)&lt;[`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type) | [`<number>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type)&gt;&gt;';
9899

99100
strictEqual(transformTypeToReferenceLink(input, {}), expected);
100101
});
102+
103+
it('should parse functions with array destructuring in callbacks returning functions with object destructuring', () => {
104+
const input =
105+
'(cb: ([first, second]: string[]) => void) => ({ id, name }: User) => boolean';
106+
107+
const expected =
108+
'(cb: ([first, second]: [`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type)[]) =&gt; `<void>`) =&gt; ({ id, name }: [`<User>`](userLink)) =&gt; [`<boolean>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#boolean_type)';
109+
110+
strictEqual(
111+
transformTypeToReferenceLink(input, { User: 'userLink' }),
112+
expected
113+
);
114+
});
101115
});

0 commit comments

Comments
 (0)