schematox 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,191 +0,0 @@
1
- import * as x from '../'
2
-
3
- describe('Type equivalence check by `tCh` utility', () => {
4
- describe('Union of literals', () => {
5
- it('valid', () => {
6
- type Expected = 'x' | 'y'
7
- type Actual = 'x' | 'y'
8
-
9
- x.tCh<Expected, Actual>()
10
- x.tCh<Actual, Expected>()
11
- })
12
-
13
- it('union has extra member', () => {
14
- type Expected = 'x' | 'y'
15
- type Actual = 'x' | 'y' | 'z'
16
-
17
- // @ts-expect-error: '"z"' is not assignable to type 'Expected'
18
- x.tCh<Expected, Actual>()
19
- x.tCh<Actual, Expected>()
20
- })
21
-
22
- it('union has `never` instead of expected member', () => {
23
- type Expected = 'x' | 'y'
24
- type Actual = 'x' | never
25
-
26
- x.tCh<Expected, Actual>()
27
- // @ts-expect-error: 'Expected' does not satisfy the constraint '"x"'
28
- x.tCh<Actual, Expected>()
29
- })
30
-
31
- it('union is `never`', () => {
32
- type Expected = 'x' | 'y'
33
- type Actual = never
34
-
35
- x.tCh<Expected, Actual>()
36
- // @ts-expect-error: Type 'string' does not satisfy the constraint 'never'.
37
- x.tCh<Actual, Expected>()
38
- })
39
- })
40
-
41
- describe('Array of primitives', () => {
42
- it('valid', () => {
43
- type Expected = Array<string | number>
44
- type Actual = Array<string | number>
45
-
46
- x.tCh<Expected, Actual>()
47
- x.tCh<Actual, Expected>()
48
- })
49
-
50
- it('array union has one extra member', () => {
51
- type Expected = Array<string | number>
52
- type Actual = Array<string | number | boolean>
53
-
54
- // @ts-expect-error: 'string | number | boolean' is not assignable to type 'string | number'
55
- x.tCh<Expected, Actual>()
56
- x.tCh<Actual, Expected>()
57
- })
58
-
59
- it('array union has `never` instead of expected memeber', () => {
60
- type Expected = Array<string | number>
61
- type Actual = Array<string | never>
62
-
63
- x.tCh<Expected, Actual>()
64
- // @ts-expect-error: 'Expected' does not satisfy the constraint 'string[]'
65
- x.tCh<Actual, Expected>()
66
- })
67
-
68
- it('array of `never`', () => {
69
- type Expected = Array<string | number>
70
- type Actual = Array<never>
71
-
72
- x.tCh<Expected, Actual>()
73
- // @ts-expect-error: 'Expected' does not satisfy the constraint 'never[]'
74
- x.tCh<Actual, Expected>()
75
- })
76
-
77
- it('array is `never`', () => {
78
- type Expected = Array<string | number>
79
- type Actual = never
80
-
81
- x.tCh<Expected, Actual>()
82
- // @ts-expect-error: Type 'Expected' does not satisfy the constraint 'never'
83
- x.tCh<Actual, Expected>()
84
- })
85
- })
86
-
87
- describe('Object of primitives', () => {
88
- it('valid', () => {
89
- type Expected = { x: string; y: number }
90
- type Actual = { x: string; y: number }
91
-
92
- x.tCh<Expected, Actual>()
93
- x.tCh<Actual, Expected>()
94
- })
95
-
96
- it('has extra property', () => {
97
- type Expected = { x: string; y: number }
98
- type Actual = { x: string; y: number; z: boolean }
99
-
100
- x.tCh<Expected, Actual>()
101
- // @ts-expect-error: Property 'z' is missing in type 'Expected' but required in type 'Actual'
102
- x.tCh<Actual, Expected>()
103
- })
104
-
105
- it('one property has `never` value', () => {
106
- type Expected = { x: string; y: number }
107
- type Actual = { x: string; y: never }
108
-
109
- x.tCh<Expected, Actual>()
110
- // @ts-expect-error Types of property 'y' are incompatible. Type 'number' is not assignable to type 'never'.
111
- x.tCh<Actual, Expected>()
112
- })
113
-
114
- it('all properties have `never` value', () => {
115
- type Expected = { x: string; y: number }
116
- type Actual = { x: never; y: never }
117
-
118
- x.tCh<Expected, Actual>()
119
- // @ts-expect-error 'Expected' does not satisfy the constraint 'Actual'
120
- x.tCh<Actual, Expected>()
121
- })
122
- })
123
- })
124
-
125
- describe('Check ParseResult utilities', () => {
126
- it('ParseResult typguards are functional', () => {
127
- const parsed = x.boolean().parse(undefined)
128
-
129
- if (parsed.success) {
130
- x.tCh<typeof parsed.data, boolean>()
131
- x.tCh<boolean, typeof parsed.data>()
132
-
133
- x.tCh<typeof parsed.error, undefined>()
134
- x.tCh<undefined, typeof parsed.error>()
135
- }
136
-
137
- if (parsed.data !== undefined) {
138
- x.tCh<typeof parsed.data, boolean>()
139
- x.tCh<boolean, typeof parsed.data>()
140
-
141
- x.tCh<typeof parsed.error, undefined>()
142
- x.tCh<undefined, typeof parsed.error>()
143
- }
144
-
145
- if (parsed.success === false) {
146
- x.tCh<typeof parsed.error, x.InvalidSubject[]>()
147
- x.tCh<x.InvalidSubject[], typeof parsed.error>()
148
-
149
- x.tCh<typeof parsed.data, undefined>()
150
- x.tCh<undefined, typeof parsed.data>()
151
- }
152
-
153
- if (parsed.error) {
154
- x.tCh<typeof parsed.error, x.InvalidSubject[]>()
155
- x.tCh<x.InvalidSubject[], typeof parsed.error>()
156
-
157
- x.tCh<typeof parsed.data, undefined>()
158
- x.tCh<undefined, typeof parsed.data>()
159
- }
160
- })
161
-
162
- it('ParseError result', () => {
163
- const invalidSubjects: x.InvalidSubject[] = [
164
- {
165
- code: x.ERROR_CODE.invalidType,
166
- path: [],
167
- schema: { type: 'string' },
168
- subject: undefined,
169
- },
170
- ]
171
-
172
- const parseError = x.error(invalidSubjects)
173
-
174
- expect('data' in parseError).toBe(false)
175
- expect(parseError.success).toBe(false)
176
- expect(parseError.error === invalidSubjects).toBe(true)
177
- })
178
-
179
- it('ParseSuccess result', () => {
180
- const validSubj = 'sample'
181
- const parsedSuccess = x.success(validSubj)
182
-
183
- expect('error' in parsedSuccess).toBe(false)
184
- expect(parsedSuccess.success).toBe(true)
185
- expect(parsedSuccess.data).toBe(validSubj)
186
- })
187
- })
188
-
189
- it('PARAMS_BY_SCHEMA_TYPE is exported', () => {
190
- expect(x.PARAMS_BY_SCHEMA_TYPE).toStrictEqual(x.PARAMS_BY_SCHEMA_TYPE)
191
- })