@@ -115,7 +115,68 @@ describe('defaultPropsHandler', () => {
115
115
expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
116
116
expect ( documentation . displayName ) . toBe ( 'bar' ) ;
117
117
} ) ;
118
+ } ) ;
119
+
120
+ describe ( 'FunctionDeclaration' , ( ) => {
121
+ it ( 'considers the function name' , ( ) => {
122
+ const definition = statement ( 'function Foo () {}' ) ;
123
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
124
+ expect ( documentation . displayName ) . toBe ( 'Foo' ) ;
125
+ } ) ;
126
+
127
+ it ( 'considers a static displayName object property' , ( ) => {
128
+ const definition = statement ( `
129
+ function Foo () {}
130
+ Foo.displayName = 'Bar';
131
+ ` ) ;
132
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
133
+ expect ( documentation . displayName ) . toBe ( 'Bar' ) ;
134
+ } ) ;
135
+ } ) ;
136
+
137
+ describe ( 'FunctionExpression' , ( ) => {
138
+ it ( 'considers the variable name' , ( ) => {
139
+ const definition = statement ( 'var Foo = function () {};' ) . get ( 'declarations' , 0 , 'init' ) ;
140
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
141
+ expect ( documentation . displayName ) . toBe ( 'Foo' ) ;
142
+ } ) ;
143
+
144
+ it ( 'considers the variable name on assign' , ( ) => {
145
+ const definition = statement ( 'Foo = function () {};' ) . get ( 'expression' , 'right' ) ;
146
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
147
+ expect ( documentation . displayName ) . toBe ( 'Foo' ) ;
148
+ } ) ;
118
149
150
+ it ( 'considers a static displayName object property over variable name' , ( ) => {
151
+ const definition = statement ( `
152
+ var Foo = function () {};
153
+ Foo.displayName = 'Bar';
154
+ ` ) ;
155
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
156
+ expect ( documentation . displayName ) . toBe ( 'Bar' ) ;
157
+ } ) ;
119
158
} ) ;
120
159
160
+ describe ( 'ArrowFunctionExpression' , ( ) => {
161
+ it ( 'considers the variable name' , ( ) => {
162
+ const definition = statement ( 'var Foo = () => {};' ) . get ( 'declarations' , 0 , 'init' ) ;
163
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
164
+ expect ( documentation . displayName ) . toBe ( 'Foo' ) ;
165
+ } ) ;
166
+
167
+ it ( 'considers the variable name on assign' , ( ) => {
168
+ const definition = statement ( 'Foo = () => {};' ) . get ( 'expression' , 'right' ) ;
169
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
170
+ expect ( documentation . displayName ) . toBe ( 'Foo' ) ;
171
+ } ) ;
172
+
173
+ it ( 'considers a static displayName object property over variable name' , ( ) => {
174
+ const definition = statement ( `
175
+ var Foo = () => {};
176
+ Foo.displayName = 'Bar';
177
+ ` ) ;
178
+ expect ( ( ) => displayNameHandler ( documentation , definition ) ) . not . toThrow ( ) ;
179
+ expect ( documentation . displayName ) . toBe ( 'Bar' ) ;
180
+ } ) ;
181
+ } ) ;
121
182
} ) ;
0 commit comments