8
8
9
9
jest . mock ( '../../Documentation' ) ;
10
10
11
- import { expression , statement } from '../../../tests/utils' ;
11
+ import {
12
+ expression ,
13
+ statement ,
14
+ noopImporter ,
15
+ makeMockImporter ,
16
+ } from '../../../tests/utils' ;
12
17
13
18
describe ( 'propTypeCompositionHandler' , ( ) => {
14
19
let getPropTypeMock ;
@@ -25,14 +30,30 @@ describe('propTypeCompositionHandler', () => {
25
30
. default ;
26
31
} ) ;
27
32
33
+ const mockImporter = makeMockImporter ( {
34
+ 'Foo.react' : statement ( `
35
+ export default Component;
36
+ function Component() {}
37
+ Component.propTypes = {
38
+ foo: 'bar'
39
+ };
40
+ ` ) . get ( 'declaration' ) ,
41
+
42
+ SharedProps : statement ( `
43
+ export default {
44
+ bar: 'baz'
45
+ };
46
+ ` ) . get ( 'declaration' ) ,
47
+ } ) ;
48
+
28
49
function test ( getSrc , parse ) {
29
50
it ( 'understands assignment from module' , ( ) => {
30
51
let definition = parse ( `
31
52
${ getSrc ( 'Foo.propTypes' ) }
32
53
var Foo = require("Foo.react");
33
54
` ) ;
34
55
35
- propTypeCompositionHandler ( documentation , definition ) ;
56
+ propTypeCompositionHandler ( documentation , definition , noopImporter ) ;
36
57
expect ( documentation . composes ) . toEqual ( [ 'Foo.react' ] ) ;
37
58
38
59
documentation = new ( require ( '../../Documentation' ) ) ( ) ;
@@ -41,7 +62,7 @@ describe('propTypeCompositionHandler', () => {
41
62
var SharedProps = require("SharedProps");
42
63
` ) ;
43
64
44
- propTypeCompositionHandler ( documentation , definition ) ;
65
+ propTypeCompositionHandler ( documentation , definition , noopImporter ) ;
45
66
expect ( documentation . composes ) . toEqual ( [ 'SharedProps' ] ) ;
46
67
} ) ;
47
68
@@ -58,9 +79,43 @@ describe('propTypeCompositionHandler', () => {
58
79
var SharedProps = require("SharedProps");
59
80
` ) ;
60
81
61
- propTypeCompositionHandler ( documentation , definition ) ;
82
+ propTypeCompositionHandler ( documentation , definition , noopImporter ) ;
62
83
expect ( documentation . composes ) . toEqual ( [ 'Foo.react' , 'SharedProps' ] ) ;
63
84
} ) ;
85
+
86
+ it ( 'does not add any composes if spreads can be fully resolved with the importer' , ( ) => {
87
+ const definitionSrc = getSrc (
88
+ `{
89
+ ...Foo.propTypes,
90
+ ...SharedProps,
91
+ }` ,
92
+ ) ;
93
+ const definition = parse ( `
94
+ ${ definitionSrc }
95
+ import Foo from "Foo.react";
96
+ import SharedProps from "SharedProps";
97
+ ` ) ;
98
+
99
+ propTypeCompositionHandler ( documentation , definition , mockImporter ) ;
100
+ expect ( documentation . composes ) . toEqual ( [ ] ) ;
101
+ } ) ;
102
+
103
+ it ( 'still adds a composes if the importer cannot resolve a value' , ( ) => {
104
+ const definitionSrc = getSrc (
105
+ `{
106
+ ...Foo.propTypes,
107
+ ...NotFound,
108
+ }` ,
109
+ ) ;
110
+ const definition = parse ( `
111
+ ${ definitionSrc }
112
+ import Foo from "Foo.react";
113
+ import NotFound from "NotFound";
114
+ ` ) ;
115
+
116
+ propTypeCompositionHandler ( documentation , definition , mockImporter ) ;
117
+ expect ( documentation . composes ) . toEqual ( [ 'NotFound' ] ) ;
118
+ } ) ;
64
119
}
65
120
66
121
describe ( 'React.createClass' , ( ) => {
0 commit comments