@@ -11,8 +11,8 @@ import { parse } from '../../../tests/utils';
11
11
import resolveToValue from '../resolveToValue' ;
12
12
13
13
describe ( 'resolveToValue' , ( ) => {
14
- function parsePath ( src ) {
15
- const root = parse ( src . trim ( ) ) ;
14
+ function parsePath ( src , options = { } ) {
15
+ const root = parse ( src . trim ( ) , options ) ;
16
16
return root . get ( 'body' , root . node . body . length - 1 , 'expression' ) ;
17
17
}
18
18
@@ -72,12 +72,35 @@ describe('resolveToValue', () => {
72
72
expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
73
73
} ) ;
74
74
75
- it ( 'resolves type cast expressions' , ( ) => {
76
- const path = parsePath ( `
75
+ describe ( 'flow' , ( ) => {
76
+ it ( 'resolves type cast expressions' , ( ) => {
77
+ const path = parsePath ( `
77
78
function foo() {}
78
79
(foo: any);
79
80
` ) ;
80
- expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
81
+ expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
82
+ } ) ;
83
+ } ) ;
84
+
85
+ describe ( 'typescript' , ( ) => {
86
+ const parseTypescript = src =>
87
+ parsePath ( src , { parserOptions : { plugins : [ 'typescript' ] } } ) ;
88
+
89
+ it ( 'resolves type as expressions' , ( ) => {
90
+ const path = parseTypescript ( `
91
+ function foo() {}
92
+ (foo as any);
93
+ ` ) ;
94
+ expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
95
+ } ) ;
96
+
97
+ it ( 'resolves type assertions' , ( ) => {
98
+ const path = parseTypescript ( `
99
+ function foo() {}
100
+ (<any> foo);
101
+ ` ) ;
102
+ expect ( resolveToValue ( path ) . node . type ) . toBe ( 'FunctionDeclaration' ) ;
103
+ } ) ;
81
104
} ) ;
82
105
83
106
describe ( 'assignments' , ( ) => {
0 commit comments