11// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Test using this disabled, see https://github.com/fastify/fast-json-stringify/pull/683
22import Ajv from 'ajv'
33import build , { restore , Schema , validLargeArrayMechanisms } from '..'
4- import { expectError , expectType } from 'tsd '
4+ import { expect } from 'tstyche '
55
66// Number schemas
77build ( {
@@ -26,9 +26,10 @@ build({
2626build ( {
2727 type : 'number'
2828} , { rounding : 'trunc' } )
29- expectError ( build ( {
29+
30+ expect ( build ) . type . not . toBeCallableWith ( {
3031 type : 'number'
31- } , { rounding : 'invalid' } ) )
32+ } , { rounding : 'invalid' } )
3233
3334// String schema
3435build ( {
@@ -153,7 +154,6 @@ build({
153154} ) ( { something : 'a string' , somethingElse : 42 } )
154155
155156// String schema with format
156-
157157build ( {
158158 type : 'string' ,
159159 format : 'date-time'
@@ -181,7 +181,6 @@ str = build({
181181 type: 'number'
182182}, { mode: 'standalone' })
183183*/
184-
185184const debugCompiled = build ( {
186185 title : 'default string' ,
187186 type : 'object' ,
@@ -191,11 +190,12 @@ const debugCompiled = build({
191190 }
192191 }
193192} , { mode : 'debug' } )
194- expectType < ReturnType < typeof build > > ( build . restore ( debugCompiled ) )
195- expectType < ReturnType < typeof build > > ( restore ( debugCompiled ) )
196193
197- expectType < string [ ] > ( build . validLargeArrayMechanisms )
198- expectType < string [ ] > ( validLargeArrayMechanisms )
194+ expect ( build . restore ( debugCompiled ) ) . type . toBe ( build ( { } as Schema ) )
195+ expect ( restore ( debugCompiled ) ) . type . toBe ( build ( { } as Schema ) )
196+
197+ expect ( build . validLargeArrayMechanisms ) . type . toBe < string [ ] > ( )
198+ expect ( validLargeArrayMechanisms ) . type . toBe < string [ ] > ( )
199199
200200/**
201201 * Schema inference
@@ -211,10 +211,11 @@ const stringify3 = build({
211211 type : 'object' ,
212212 properties : { a : { type : 'string' } } ,
213213} )
214+
214215stringify3 < InferenceSchema > ( { id : '123' } )
215216stringify3 < InferenceSchema > ( { a : 123 , id : '123' } )
216- expectError ( stringify3 < InferenceSchema > ( { anotherOne : 'bar' } ) )
217- expectError ( stringify3 < Schema > ( { a : 'bar' } ) )
217+ expect ( stringify3 < InferenceSchema > ) . type . not . toBeCallableWith ( { anotherOne : 'bar' } )
218+ expect ( stringify3 < Schema > ) . type . not . toBeCallableWith ( { a : 'bar' } )
218219
219220// Without inference
220221const stringify4 = build ( {
@@ -231,29 +232,28 @@ const stringify5 = build({
231232 type : 'string' ,
232233} )
233234stringify5 ( 'foo' )
234- expectError ( stringify5 ( { id : '123' } ) )
235+ expect ( stringify5 ) . type . not . toBeCallableWith ( { id : '123' } )
235236
236237// Without inference - null type
237238const stringify6 = build ( {
238239 type : 'null' ,
239240} )
240241stringify6 ( null )
241- expectError ( stringify6 ( 'a string' ) )
242+ expect ( stringify6 ) . type . not . toBeCallableWith ( 'a string' )
242243
243244// Without inference - boolean type
244245const stringify7 = build ( {
245246 type : 'boolean' ,
246247} )
247248stringify7 ( true )
248- expectError ( stringify7 ( 'a string' ) )
249+ expect ( stringify7 ) . type . not . toBeCallableWith ( 'a string' )
249250
250251// largeArrayMechanism
251-
252252build ( { } , { largeArrayMechanism : 'json-stringify' } )
253253build ( { } , { largeArrayMechanism : 'default' } )
254- expectError ( build ( { } as Schema , { largeArrayMechanism : 'invalid' } ) )
254+ expect ( build ) . type . not . toBeCallableWith ( { } as Schema , { largeArrayMechanism : 'invalid' } )
255255
256256build ( { } , { largeArraySize : 2000 } )
257257build ( { } , { largeArraySize : '2e4' } )
258258build ( { } , { largeArraySize : 2n } )
259- expectError ( build ( { } as Schema , { largeArraySize : [ 'asdf' ] } ) )
259+ expect ( build ) . type . not . toBeCallableWith ( { } as Schema , { largeArraySize : [ 'asdf' ] } )
0 commit comments