Skip to content

Commit d1c0ed6

Browse files
committed
test: fix type testing
1 parent bf44b86 commit d1c0ed6

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

docs/tsconfig.json

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
{
2-
// "extends": "@textea/dev-kit/config/tsconfig.root.json", // todo: to remove
32
"compilerOptions": {
43
"paths": {
5-
"@textea/json-viewer": [
6-
"../src/index"
7-
]
4+
"@textea/json-viewer": ["../src/index"]
85
},
96
"jsx": "preserve",
107
"incremental": true,
118
"noEmit": true,
12-
// "target": "es5",
139
"target": "ES2020",
14-
"lib": [
15-
"dom",
16-
"dom.iterable",
17-
"esnext"
18-
],
10+
"lib": ["dom", "dom.iterable", "esnext"],
1911
"allowJs": true,
2012
"skipLibCheck": true,
2113
"strict": false,
@@ -24,14 +16,8 @@
2416
"module": "esnext",
2517
"moduleResolution": "node",
2618
"resolveJsonModule": true,
27-
"isolatedModules": true,
19+
"isolatedModules": true
2820
},
29-
"include": [
30-
"next-env.d.ts",
31-
"**/*.ts",
32-
"**/*.tsx"
33-
],
34-
"exclude": [
35-
"node_modules"
36-
]
21+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
22+
"exclude": ["node_modules"]
3723
}

tests/tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {
4+
"@textea/json-viewer": ["../src/index"]
5+
},
6+
"jsx": "preserve",
7+
"incremental": true,
8+
"noEmit": true,
9+
"target": "ES2020",
10+
"lib": ["dom", "dom.iterable", "esnext"],
11+
"allowJs": true,
12+
"skipLibCheck": true,
13+
"strict": false,
14+
"forceConsistentCasingInFileNames": true,
15+
"esModuleInterop": true,
16+
"module": "esnext",
17+
"moduleResolution": "node",
18+
"resolveJsonModule": true,
19+
"isolatedModules": true
20+
},
21+
"include": ["**/*.ts", "**/*.tsx"],
22+
"exclude": ["node_modules"]
23+
}

tests/util.test.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expectTypeOf } from 'expect-type'
22
import type { ComponentType } from 'react'
33
import { describe, expect, test } from 'vitest'
44

5-
import type { DataItemProps } from '../src'
5+
import type { DataItemProps, Path } from '../src'
66
import { applyValue, createDataType, isCycleReference } from '../src'
77
import { segmentArray } from '../src/utils'
88

@@ -95,17 +95,10 @@ describe('function createDataType', () => {
9595
}
9696
)
9797
expectTypeOf(dataType).toEqualTypeOf<{
98-
is:(value: unknown) => value is string
98+
is:(value: unknown, path: Path) => value is string
9999
Component: ComponentType<DataItemProps<string>>
100100
}>()
101-
const someValue: unknown = null
102101
expectTypeOf(dataType.is).returns.toBeBoolean()
103-
if (dataType.is(someValue)) {
104-
expectTypeOf(someValue).toMatchTypeOf<string>()
105-
} else {
106-
expectTypeOf(someValue).not.toMatchTypeOf<string>()
107-
expectTypeOf(someValue).toMatchTypeOf<unknown>()
108-
}
109102
expect(dataType.is).toBeTypeOf('function')
110103
expect(dataType.Component).toBeTypeOf('function')
111104
})
@@ -125,7 +118,7 @@ describe('function createDataType', () => {
125118
}
126119
)
127120
expectTypeOf(dataType).toEqualTypeOf<{
128-
is:(value: unknown) => value is string
121+
is:(value: unknown, path: Path) => value is string
129122
Component: ComponentType<DataItemProps<string>>
130123
Editor: ComponentType<DataItemProps<string>>
131124
}>()
@@ -155,7 +148,7 @@ describe('function createDataType', () => {
155148
}
156149
)
157150
expectTypeOf(dataType).toEqualTypeOf<{
158-
is:(value: unknown) => value is string
151+
is:(value: unknown, path: Path) => value is string
159152
Component: ComponentType<DataItemProps<string>>
160153
PreComponent: ComponentType<DataItemProps<string>>
161154
PostComponent: ComponentType<DataItemProps<string>>
@@ -191,7 +184,7 @@ describe('function createDataType', () => {
191184
}
192185
)
193186
expectTypeOf(dataType).toEqualTypeOf<{
194-
is:(value: unknown) => value is string
187+
is:(value: unknown, path: Path) => value is string
195188
Component: ComponentType<DataItemProps<string>>
196189
Editor: ComponentType<DataItemProps<string>>
197190
PreComponent: ComponentType<DataItemProps<string>>

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"moduleResolution": "node",
1111
"allowSyntheticDefaultImports": true
1212
},
13-
"include": ["src/**/*.ts"],
13+
"include": ["./src"],
1414
"exclude": ["node_modules"]
1515
}

0 commit comments

Comments
 (0)