@@ -174,6 +174,18 @@ describe('defaultPropsHandler', () => {
174
174
expect ( documentation . displayName ) . toBe ( 'Foo' ) ;
175
175
} ) ;
176
176
177
+ it ( 'considers the variable name even if wrapped' , ( ) => {
178
+ const definition = statement ( 'var Foo = React.forwardRef(() => {});' ) . get (
179
+ 'declarations' ,
180
+ 0 ,
181
+ 'init' ,
182
+ 'arguments' ,
183
+ 0 ,
184
+ ) ;
185
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
186
+ expect ( documentation . displayName ) . toBe ( 'Foo' ) ;
187
+ } ) ;
188
+
177
189
it ( 'considers the variable name on assign' , ( ) => {
178
190
const definition = statement ( 'Foo = () => {};' ) . get (
179
191
'expression' ,
@@ -183,6 +195,17 @@ describe('defaultPropsHandler', () => {
183
195
expect ( documentation . displayName ) . toBe ( 'Foo' ) ;
184
196
} ) ;
185
197
198
+ it ( 'considers the variable name on assign even if wrapped' , ( ) => {
199
+ const definition = statement ( 'Foo = React.forwardRef(() => {});' ) . get (
200
+ 'expression' ,
201
+ 'right' ,
202
+ 'arguments' ,
203
+ 0 ,
204
+ ) ;
205
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
206
+ expect ( documentation . displayName ) . toBe ( 'Foo' ) ;
207
+ } ) ;
208
+
186
209
it ( 'considers a static displayName object property over variable name' , ( ) => {
187
210
const definition = statement ( `
188
211
var Foo = () => {};
@@ -191,5 +214,14 @@ describe('defaultPropsHandler', () => {
191
214
expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
192
215
expect ( documentation . displayName ) . toBe ( 'Bar' ) ;
193
216
} ) ;
217
+
218
+ it ( 'considers a static displayName object property over variable name even if wrapped' , ( ) => {
219
+ const definition = statement ( `
220
+ var Foo = React.forwardRef(() => {});
221
+ Foo.displayName = 'Bar';
222
+ ` ) ;
223
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
224
+ expect ( documentation . displayName ) . toBe ( 'Bar' ) ;
225
+ } ) ;
194
226
} ) ;
195
227
} ) ;
0 commit comments