Skip to content

Commit de10109

Browse files
phateddanez
authored andcommitted
Add importer tests for propDocblockHandler
1 parent 69fcc37 commit de10109

File tree

1 file changed

+58
-9
lines changed

1 file changed

+58
-9
lines changed

src/handlers/__tests__/propDocblockHandler-test.js

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
jest.mock('../../Documentation');
1010

11-
import { expression, statement } from '../../../tests/utils';
11+
import { expression, statement, noopImporter, makeMockImporter } from '../../../tests/utils';
1212

1313
describe('propDocBlockHandler', () => {
1414
let documentation;
@@ -19,6 +19,17 @@ describe('propDocBlockHandler', () => {
1919
propDocBlockHandler = require('../propDocBlockHandler').default;
2020
});
2121

22+
const mockImporter = makeMockImporter({
23+
props: statement(`
24+
export default {
25+
/**
26+
* A comment on imported props
27+
*/
28+
foo: Prop.bool,
29+
};
30+
`).get('declaration'),
31+
});
32+
2233
function test(getSrc, parse) {
2334
it('finds docblocks for prop types', () => {
2435
const definition = parse(
@@ -36,7 +47,7 @@ describe('propDocBlockHandler', () => {
3647
),
3748
);
3849

39-
propDocBlockHandler(documentation, definition);
50+
propDocBlockHandler(documentation, definition, noopImporter);
4051
expect(documentation.descriptors).toEqual({
4152
foo: {
4253
description: 'Foo comment',
@@ -62,7 +73,7 @@ describe('propDocBlockHandler', () => {
6273
),
6374
);
6475

65-
propDocBlockHandler(documentation, definition);
76+
propDocBlockHandler(documentation, definition, noopImporter);
6677
expect(documentation.descriptors).toEqual({
6778
foo: {
6879
description:
@@ -89,7 +100,7 @@ describe('propDocBlockHandler', () => {
89100
),
90101
);
91102

92-
propDocBlockHandler(documentation, definition);
103+
propDocBlockHandler(documentation, definition, noopImporter);
93104
expect(documentation.descriptors).toEqual({
94105
foo: {
95106
description: 'Foo comment',
@@ -113,7 +124,7 @@ describe('propDocBlockHandler', () => {
113124
),
114125
);
115126

116-
propDocBlockHandler(documentation, definition);
127+
propDocBlockHandler(documentation, definition, noopImporter);
117128
expect(documentation.descriptors).toEqual({
118129
foo: {
119130
description: 'Foo comment',
@@ -137,7 +148,7 @@ describe('propDocBlockHandler', () => {
137148
),
138149
);
139150

140-
propDocBlockHandler(documentation, definition);
151+
propDocBlockHandler(documentation, definition, noopImporter);
141152
expect(documentation.descriptors).toEqual({
142153
foo: {
143154
description: 'Foo comment',
@@ -156,13 +167,51 @@ describe('propDocBlockHandler', () => {
156167
};
157168
`);
158169

159-
propDocBlockHandler(documentation, definition);
170+
propDocBlockHandler(documentation, definition, noopImporter);
160171
expect(documentation.descriptors).toEqual({
161172
foo: {
162173
description: 'Foo comment',
163174
},
164175
});
165176
});
177+
178+
it('resolves imported variables', () => {
179+
const definition = parse(`
180+
${getSrc('Props')}
181+
import Props from 'props';
182+
`);
183+
184+
propDocBlockHandler(documentation, definition, mockImporter);
185+
expect(documentation.descriptors).toEqual({
186+
foo: {
187+
description: 'A comment on imported props',
188+
},
189+
});
190+
});
191+
192+
it('resolves imported variables that are spread', () => {
193+
const definition = parse(`
194+
${getSrc('Props')}
195+
import ExtraProps from 'props';
196+
var Props = {
197+
...ExtraProps,
198+
/**
199+
* Bar comment
200+
*/
201+
bar: Prop.bool,
202+
}
203+
`);
204+
205+
propDocBlockHandler(documentation, definition, mockImporter);
206+
expect(documentation.descriptors).toEqual({
207+
foo: {
208+
description: 'A comment on imported props',
209+
},
210+
bar: {
211+
description: 'Bar comment',
212+
},
213+
});
214+
});
166215
}
167216

168217
describe('React.createClass', () => {
@@ -200,9 +249,9 @@ describe('propDocBlockHandler', () => {
200249

201250
it('does not error if propTypes cannot be found', () => {
202251
let definition = expression('{fooBar: 42}');
203-
expect(() => propDocBlockHandler(documentation, definition)).not.toThrow();
252+
expect(() => propDocBlockHandler(documentation, definition, noopImporter)).not.toThrow();
204253

205254
definition = statement('class Foo {}');
206-
expect(() => propDocBlockHandler(documentation, definition)).not.toThrow();
255+
expect(() => propDocBlockHandler(documentation, definition, noopImporter)).not.toThrow();
207256
});
208257
});

0 commit comments

Comments
 (0)