11import type * as d from '../../../declarations' ;
2- import * as Util from '../../../utils/util' ;
32import { generatePropTypes } from '../generate-prop-types' ;
43import * as StencilTypes from '../stencil-types' ;
54import { stubComponentCompilerMeta } from './ComponentCompilerMeta.stub' ;
@@ -13,7 +12,6 @@ describe('generate-prop-types', () => {
1312 ReturnType < typeof StencilTypes . updateTypeIdentifierNames > ,
1413 Parameters < typeof StencilTypes . updateTypeIdentifierNames >
1514 > ;
16- let getTextDocsSpy : jest . SpyInstance < ReturnType < typeof Util . getTextDocs > , Parameters < typeof Util . getTextDocs > > ;
1715
1816 beforeEach ( ( ) => {
1917 updateTypeIdentifierNamesSpy = jest . spyOn ( StencilTypes , 'updateTypeIdentifierNames' ) ;
@@ -25,14 +23,10 @@ describe('generate-prop-types', () => {
2523 initialType : string ,
2624 ) => initialType ,
2725 ) ;
28-
29- getTextDocsSpy = jest . spyOn ( Util , 'getTextDocs' ) ;
30- getTextDocsSpy . mockReturnValue ( '' ) ;
3126 } ) ;
3227
3328 afterEach ( ( ) => {
3429 updateTypeIdentifierNamesSpy . mockRestore ( ) ;
35- getTextDocsSpy . mockRestore ( ) ;
3630 } ) ;
3731
3832 it ( 'returns an empty array when no props are provided' , ( ) => {
@@ -141,5 +135,59 @@ describe('generate-prop-types', () => {
141135
142136 expect ( actualTypeInfo ) . toEqual ( expectedTypeInfo ) ;
143137 } ) ;
138+
139+ it ( 'appends `@readonly` to jsdoc when the property has a getter and no setter' , ( ) => {
140+ const stubImportTypes = stubTypesImportData ( ) ;
141+ const componentMeta = stubComponentCompilerMeta ( {
142+ properties : [
143+ stubComponentCompilerProperty ( {
144+ getter : true ,
145+ setter : false ,
146+ } ) ,
147+ ] ,
148+ } ) ;
149+
150+ const expectedTypeInfo : d . TypeInfo = [
151+ {
152+ jsdoc : '@readonly' ,
153+ internal : false ,
154+ name : 'propName' ,
155+ optional : false ,
156+ required : false ,
157+ type : 'UserCustomPropType' ,
158+ } ,
159+ ] ;
160+
161+ const actualTypeInfo = generatePropTypes ( componentMeta , stubImportTypes ) ;
162+
163+ expect ( actualTypeInfo ) . toEqual ( expectedTypeInfo ) ;
164+ } ) ;
165+
166+ it ( 'does not include `@readonly` to jsdoc when the property has a getter and a setter' , ( ) => {
167+ const stubImportTypes = stubTypesImportData ( ) ;
168+ const componentMeta = stubComponentCompilerMeta ( {
169+ properties : [
170+ stubComponentCompilerProperty ( {
171+ getter : true ,
172+ setter : true ,
173+ } ) ,
174+ ] ,
175+ } ) ;
176+
177+ const expectedTypeInfo : d . TypeInfo = [
178+ {
179+ jsdoc : '' ,
180+ internal : false ,
181+ name : 'propName' ,
182+ optional : false ,
183+ required : false ,
184+ type : 'UserCustomPropType' ,
185+ } ,
186+ ] ;
187+
188+ const actualTypeInfo = generatePropTypes ( componentMeta , stubImportTypes ) ;
189+
190+ expect ( actualTypeInfo ) . toEqual ( expectedTypeInfo ) ;
191+ } ) ;
144192 } ) ;
145193} ) ;
0 commit comments