-
Notifications
You must be signed in to change notification settings - Fork 661
Expand file tree
/
Copy pathts-utils.patterns.test.ts
More file actions
44 lines (36 loc) · 2.15 KB
/
ts-utils.patterns.test.ts
File metadata and controls
44 lines (36 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import path from 'path'
import {describe, it, expect} from 'vitest'
import {parseTypeInfo} from '../ts-utils'
const directory = path.resolve(import.meta.dirname)
const FIXTURE_PATH = path.join(directory, 'fixtures')
describe('getPropTypeForComponent', {timeout: 30_000}, () => {
it('extracts props for FunctionComponent', () => {
const info = parseTypeInfo(FIXTURE_PATH, 'FunctionComponent')
expect(info.props.foo).toMatchObject({name: 'foo', type: 'string', required: true})
expect(info.props.bar).toMatchObject({name: 'bar', type: 'number', required: false})
expect(info.props.baz).toMatchObject({name: 'baz', type: 'boolean', required: false})
}, 10000)
it('extracts props for ArrowComponent', () => {
const info = parseTypeInfo(FIXTURE_PATH, 'ArrowComponent')
expect(info.props.alpha).toMatchObject({name: 'alpha', type: 'number', required: true})
expect(info.props.beta).toMatchObject({name: 'beta', type: 'string', required: false})
})
it('extracts props for DefaultExportComponent', () => {
const info = parseTypeInfo(FIXTURE_PATH, 'DefaultExportComponent')
expect(info.props.a).toMatchObject({name: 'a', type: 'string', required: true})
expect(info.props.b).toMatchObject({name: 'b', type: 'boolean', required: false})
})
it('extracts props for ArrowComponent w/ indirection', () => {
const info = parseTypeInfo(path.join(FIXTURE_PATH, 'exports'), 'ArrowComponent')
expect(info.props.alpha).toMatchObject({name: 'alpha', type: 'number', required: true})
expect(info.props.beta).toMatchObject({name: 'beta', type: 'string', required: false})
})
it('extracts props for NestedComponent', () => {
const info = parseTypeInfo(FIXTURE_PATH, 'NestedComponent')
expect(info.props.bar).toMatchObject({name: 'bar', type: 'string', required: true})
expect(info.subComponents).toHaveProperty('SubComponent')
expect(info.subComponents?.SubComponent.props.foo).toMatchObject({name: 'foo', type: 'string', required: true})
expect(info.subComponents).toHaveProperty('SubComponent2')
expect(info.subComponents?.SubComponent2.props.baz).toMatchObject({name: 'baz', type: 'number', required: true})
})
})