-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: New tests and fix for expressionTo with Spread and Methods
- Loading branch information
Showing
5 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
src/utils/__tests__/__snapshots__/resolveGenericTypeAnnotations-test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`resolveGenericTypeAnnotation resolves type 1`] = ` | ||
Node { | ||
"callProperties": Array [], | ||
"end": 57, | ||
"exact": false, | ||
"extra": undefined, | ||
"indexers": Array [], | ||
"inexact": false, | ||
"innerComments": undefined, | ||
"internalSlots": Array [], | ||
"leadingComments": undefined, | ||
"loc": SourceLocation { | ||
"end": Position { | ||
"column": 34, | ||
"line": 3, | ||
}, | ||
"filename": undefined, | ||
"identifierName": undefined, | ||
"start": Position { | ||
"column": 21, | ||
"line": 3, | ||
}, | ||
}, | ||
"properties": Array [ | ||
Node { | ||
"end": 55, | ||
"extra": undefined, | ||
"innerComments": undefined, | ||
"key": Node { | ||
"end": 47, | ||
"extra": undefined, | ||
"innerComments": undefined, | ||
"leadingComments": undefined, | ||
"loc": SourceLocation { | ||
"end": Position { | ||
"column": 24, | ||
"line": 3, | ||
}, | ||
"filename": undefined, | ||
"identifierName": "x", | ||
"start": Position { | ||
"column": 23, | ||
"line": 3, | ||
}, | ||
}, | ||
"name": "x", | ||
"range": undefined, | ||
"start": 46, | ||
"trailingComments": undefined, | ||
"type": "Identifier", | ||
}, | ||
"kind": "init", | ||
"leadingComments": undefined, | ||
"loc": SourceLocation { | ||
"end": Position { | ||
"column": 32, | ||
"line": 3, | ||
}, | ||
"filename": undefined, | ||
"identifierName": undefined, | ||
"start": Position { | ||
"column": 23, | ||
"line": 3, | ||
}, | ||
}, | ||
"method": false, | ||
"optional": false, | ||
"proto": false, | ||
"range": undefined, | ||
"start": 46, | ||
"static": false, | ||
"trailingComments": undefined, | ||
"type": "ObjectTypeProperty", | ||
"value": Node { | ||
"end": 55, | ||
"extra": undefined, | ||
"innerComments": undefined, | ||
"leadingComments": undefined, | ||
"loc": SourceLocation { | ||
"end": Position { | ||
"column": 32, | ||
"line": 3, | ||
}, | ||
"filename": undefined, | ||
"identifierName": undefined, | ||
"start": Position { | ||
"column": 26, | ||
"line": 3, | ||
}, | ||
}, | ||
"range": undefined, | ||
"start": 49, | ||
"trailingComments": undefined, | ||
"type": "StringTypeAnnotation", | ||
}, | ||
"variance": null, | ||
}, | ||
], | ||
"range": undefined, | ||
"start": 44, | ||
"trailingComments": undefined, | ||
"type": "ObjectTypeAnnotation", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { expression, noopImporter } from '../../../tests/utils'; | ||
import { Array as expressionToArray } from '../expressionTo'; | ||
|
||
describe('expressionTo', () => { | ||
describe('MemberExpression', () => { | ||
it('with only identifiers', () => { | ||
expect( | ||
expressionToArray(expression('foo.bar.baz'), noopImporter), | ||
).toEqual(['foo', 'bar', 'baz']); | ||
}); | ||
|
||
it('with one computed literal', () => { | ||
expect( | ||
expressionToArray(expression('foo["bar"].baz'), noopImporter), | ||
).toEqual(['foo', '"bar"', 'baz']); | ||
}); | ||
|
||
it('with one computed identifier', () => { | ||
expect( | ||
expressionToArray(expression('foo[bar].baz'), noopImporter), | ||
).toEqual(['foo', 'bar', 'baz']); | ||
}); | ||
|
||
it('with one computed object', () => { | ||
expect( | ||
expressionToArray(expression('foo[{ a: "true"}].baz'), noopImporter), | ||
).toEqual(['foo', '{a: "true"}', 'baz']); | ||
}); | ||
|
||
it('with one computed object with spread', () => { | ||
expect( | ||
expressionToArray(expression('foo[{ ...a }].baz'), noopImporter), | ||
).toEqual(['foo', '{...a}', 'baz']); | ||
}); | ||
|
||
it('with one computed object with method', () => { | ||
expect( | ||
expressionToArray(expression('foo[{ a(){} }].baz'), noopImporter), | ||
).toEqual(['foo', '{a: <function>}', 'baz']); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expression, statement } from '../../../tests/utils'; | ||
import isUnreachableFlowType from '../isUnreachableFlowType'; | ||
|
||
describe('isUnreachableFlowType', () => { | ||
it('considers Identifier as unreachable', () => { | ||
expect(isUnreachableFlowType(expression('foo'))).toBe(true); | ||
}); | ||
|
||
it('considers ImportDeclaration as unreachable', () => { | ||
expect(isUnreachableFlowType(statement('import x from "";'))).toBe(true); | ||
}); | ||
|
||
it('considers CallExpression as unreachable', () => { | ||
expect(isUnreachableFlowType(expression('foo()'))).toBe(true); | ||
}); | ||
|
||
it('considers VariableDeclaration not as unreachable', () => { | ||
expect(isUnreachableFlowType(statement('const x = 1;'))).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { statement, noopImporter } from '../../../tests/utils'; | ||
import resolveGenericTypeAnnotation from '../resolveGenericTypeAnnotation'; | ||
|
||
describe('resolveGenericTypeAnnotation', () => { | ||
it('resolves type', () => { | ||
const code = ` | ||
var x: Props; | ||
type Props = { x: string }; | ||
`; | ||
expect( | ||
resolveGenericTypeAnnotation( | ||
statement(code).get( | ||
'declarations', | ||
0, | ||
'id', | ||
'typeAnnotation', | ||
'typeAnnotation', | ||
), | ||
noopImporter, | ||
), | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters