1- const { createPackageDoc} = require ( "@webdoc/model" ) ;
1+
2+ const { createPackageDoc, findDoc} = require ( "@webdoc/model" ) ;
23const { parse} = require ( "../lib/parse" ) ;
34
45const expect = require ( "chai" ) . expect ;
56
6- describe ( "@webdoc/parser.parser " , function ( ) {
7+ describe ( "@webdoc/parser.parse (Typescript) " , function ( ) {
78 it ( "should infer access, default value, and type for fields" , function ( ) {
89 const docs = parse ( [ {
910 content : `
10- /** Example class */
11- class Example {
12- /**
13- * Field description
14- */
15- protected readonly field: boolean = true;
16- }
17- ` ,
11+ /** Example class */
12+ class Example {
13+ /**
14+ * Field description
15+ */
16+ protected readonly field: boolean = true;
17+ }
18+ `,
1819 path : ".ts" ,
1920 package : createPackageDoc ( ) ,
2021 } ] ) ;
@@ -33,4 +34,25 @@ class Example {
3334 // in a PR for different issue)
3435 expect ( fieldDoc . brief ) . to . equal ( " Field description" ) ;
3536 } ) ;
37+
38+ it ( "should infer access, returns for methods" , function ( ) {
39+ const docs = parse ( [ {
40+ content : `
41+ class Resource {
42+ /** Method */
43+ protected onPlay(): void {
44+ this._playing = true;
45+ }
46+ }
47+ ` ,
48+ path : ".ts" ,
49+ package : createPackageDoc ( ) ,
50+ } ] ) ;
51+
52+ const methodDoc = findDoc ( "Resource.onPlay" , docs ) ;
53+
54+ expect ( methodDoc . name ) . to . equal ( "onPlay" ) ;
55+ expect ( methodDoc . access ) . to . equal ( "protected" ) ;
56+ expect ( methodDoc . returns [ 0 ] . dataType [ 0 ] ) . to . equal ( "void" ) ;
57+ } ) ;
3658} ) ;
0 commit comments