@@ -5,6 +5,7 @@ import MarkdownIt from 'markdown-it';
5
5
import {
6
6
safelyJoinTokens ,
7
7
extractStringEnum ,
8
+ extractReturnType ,
8
9
rawTypeToTypeInformation ,
9
10
parseHeadingTags ,
10
11
findNextList ,
@@ -366,6 +367,79 @@ foo`),
366
367
} ) ;
367
368
} ) ;
368
369
370
+ describe ( 'extractReturnType()' , ( ) => {
371
+ it ( 'should handle simple return types with descriptions' , ( ) => {
372
+ const intTokens = getTokens ( `Returns \`Integer\` - The request id used for the request.` ) ;
373
+ const intRet = extractReturnType ( intTokens ) ;
374
+ expect ( intRet . parsedReturnType ) . toEqual ( {
375
+ collection : false ,
376
+ type : 'Integer' ,
377
+ } ) ;
378
+
379
+ const stringTokens = getTokens ( `Returns \`String\` - Returns the WebRTC IP Handling Policy.` ) ;
380
+ const stringRet = extractReturnType ( stringTokens ) ;
381
+ expect ( stringRet . parsedReturnType ) . toEqual ( {
382
+ collection : false ,
383
+ possibleValues : null ,
384
+ type : 'String' ,
385
+ } ) ;
386
+ } ) ;
387
+
388
+ it ( 'should handle Promises with void inner types' , ( ) => {
389
+ const promiseTokens = getTokens (
390
+ `Returns \`Promise<void>\` - Indicates whether the snapshot has been created successfully.` ,
391
+ ) ;
392
+ const promiseRet = extractReturnType ( promiseTokens ) ;
393
+ expect ( promiseRet . parsedReturnType ) . toEqual ( {
394
+ collection : false ,
395
+ innerTypes : [
396
+ {
397
+ collection : false ,
398
+ type : 'void' ,
399
+ } ,
400
+ ] ,
401
+ type : 'Promise' ,
402
+ } ) ;
403
+ } ) ;
404
+
405
+ it ( 'should handle Promises with non-void inner types' , ( ) => {
406
+ const promiseTokens = getTokens (
407
+ `Returns \`Promise<Buffer>\` - Resolves with the generated PDF data.` ,
408
+ ) ;
409
+ const promiseRet = extractReturnType ( promiseTokens ) ;
410
+ expect ( promiseRet . parsedReturnType ) . toEqual ( {
411
+ collection : false ,
412
+ innerTypes : [
413
+ {
414
+ collection : false ,
415
+ type : 'Buffer' ,
416
+ } ,
417
+ ] ,
418
+ type : 'Promise' ,
419
+ } ) ;
420
+ } ) ;
421
+
422
+ it ( 'should handle custom return types' , ( ) => {
423
+ const customTokens = getTokens (
424
+ `Returns \`WebContents\` - A WebContents instance with the given ID.` ,
425
+ ) ;
426
+ const customRet = extractReturnType ( customTokens ) ;
427
+ expect ( customRet . parsedReturnType ) . toEqual ( {
428
+ collection : false ,
429
+ type : 'WebContents' ,
430
+ } ) ;
431
+ } ) ;
432
+
433
+ it ( 'should handle return types with no descriptions' , ( ) => {
434
+ const printerTokens = getTokens ( `Returns [\`PrinterInfo[]\`](structures/printer-info.md)` ) ;
435
+ const printerRet = extractReturnType ( printerTokens ) ;
436
+ expect ( printerRet . parsedReturnType ) . toEqual ( {
437
+ collection : true ,
438
+ type : 'PrinterInfo' ,
439
+ } ) ;
440
+ } ) ;
441
+ } ) ;
442
+
369
443
describe ( 'getTopLevelGenericType()' , ( ) => {
370
444
it ( 'should return null if there is no generic in the type' , ( ) => {
371
445
expect ( getTopLevelGenericType ( 'Foo' ) ) . toEqual ( null ) ;
0 commit comments