@@ -34,7 +34,7 @@ describe('Property-Based Tests', () => {
3434 test ( '无效 JSON 应该返回 fallback 值' , ( ) => {
3535 fc . assert (
3636 fc . property (
37- fc . string ( ) . filter ( ( s ) => {
37+ fc . string ( ) . filter ( ( s : string ) => {
3838 try {
3939 JSON . parse ( s )
4040 return false // 有效 JSON,过滤掉
@@ -81,7 +81,7 @@ describe('Property-Based Tests', () => {
8181 fc . assert (
8282 fc . property (
8383 fc . dictionary (
84- fc . string ( { minLength : 1 } ) . filter ( ( s ) => ! s . includes ( '\0' ) ) ,
84+ fc . string ( { minLength : 1 } ) . filter ( ( s : string ) => ! s . includes ( '\0' ) ) ,
8585 fc . string ( ) . filter ( ( s ) => ! s . includes ( '\0' ) )
8686 ) ,
8787 ( headers ) => {
@@ -181,15 +181,19 @@ describe('Property-Based Tests', () => {
181181
182182 test ( '不同输入应该产生不同 hash(高概率)' , ( ) => {
183183 fc . assert (
184- fc . property ( fc . string ( { minLength : 1 } ) , fc . string ( { minLength : 1 } ) , ( input1 , input2 ) => {
185- fc . pre ( input1 !== input2 ) // 前置条件:输入不同
184+ fc . property (
185+ fc . string ( { minLength : 1 } ) ,
186+ fc . string ( { minLength : 1 } ) ,
187+ ( input1 : string , input2 : string ) => {
188+ fc . pre ( input1 !== input2 ) // 前置条件:输入不同
186189
187- const hash1 = generateHash ( input1 )
188- const hash2 = generateHash ( input2 )
190+ const hash1 = generateHash ( input1 )
191+ const hash2 = generateHash ( input2 )
189192
190- // 不同输入应该产生不同 hash(碰撞概率极低)
191- expect ( hash1 ) . not . toBe ( hash2 )
192- } ) ,
193+ // 不同输入应该产生不同 hash(碰撞概率极低)
194+ expect ( hash1 ) . not . toBe ( hash2 )
195+ }
196+ ) ,
193197 { numRuns : 50 }
194198 )
195199 } )
@@ -216,9 +220,9 @@ describe('Property-Based Tests', () => {
216220 test ( 'header 查询应该大小写不敏感' , ( ) => {
217221 fc . assert (
218222 fc . property (
219- fc . string ( { minLength : 1 } ) . filter ( ( s ) => / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 - ] * $ / . test ( s ) ) ,
223+ fc . string ( { minLength : 1 } ) . filter ( ( s : string ) => / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 - ] * $ / . test ( s ) ) ,
220224 fc . string ( ) ,
221- ( headerName , headerValue ) => {
225+ ( headerName : string , headerValue : string ) => {
222226 const headers = { [ headerName ] : headerValue }
223227 const pipe = new RequestHeaderPipe ( headers )
224228
@@ -240,13 +244,13 @@ describe('Property-Based Tests', () => {
240244 test ( '混合大小写的 header 名称应该正确处理' , ( ) => {
241245 fc . assert (
242246 fc . property (
243- fc . string ( { minLength : 1 } ) . filter ( ( s ) => / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 - ] * $ / . test ( s ) ) ,
247+ fc . string ( { minLength : 1 } ) . filter ( ( s : string ) => / ^ [ a - z A - Z ] [ a - z A - Z 0 - 9 - ] * $ / . test ( s ) ) ,
244248 fc . string ( ) ,
245- ( headerName , headerValue ) => {
249+ ( headerName : string , headerValue : string ) => {
246250 // 创建混合大小写的名称
247251 const mixedCase = headerName
248252 . split ( '' )
249- . map ( ( c , i ) => ( i % 2 === 0 ? c . toUpperCase ( ) : c . toLowerCase ( ) ) )
253+ . map ( ( c : string , i : number ) => ( i % 2 === 0 ? c . toUpperCase ( ) : c . toLowerCase ( ) ) )
250254 . join ( '' )
251255
252256 const headers = { [ headerName ] : headerValue }
@@ -295,7 +299,7 @@ describe('Property-Based Tests', () => {
295299 describe ( 'Property 15: requestId 唯一性' , ( ) => {
296300 test ( '生成的 requestId 应该唯一' , ( ) => {
297301 fc . assert (
298- fc . property ( fc . integer ( { min : 10 , max : 50 } ) , ( count ) => {
302+ fc . property ( fc . integer ( { min : 10 , max : 50 } ) , ( count : number ) => {
299303 const requestIds = new Set < string > ( )
300304
301305 for ( let i = 0 ; i < count ; i ++ ) {
@@ -314,11 +318,11 @@ describe('Property-Based Tests', () => {
314318 fc . assert (
315319 fc . property (
316320 fc . array ( fc . nat ( { max : 1000 } ) , { minLength : 2 , maxLength : 10 } ) ,
317- ( deltas ) => {
321+ ( deltas : number [ ] ) => {
318322 let timestamp = Date . now ( )
319323 const timestamps : number [ ] = [ timestamp ]
320324
321- deltas . forEach ( ( delta ) => {
325+ deltas . forEach ( ( delta : number ) => {
322326 timestamp += delta
323327 timestamps . push ( timestamp )
324328 } )
@@ -337,7 +341,7 @@ describe('Property-Based Tests', () => {
337341 describe ( 'Property 18: CDP 响应格式' , ( ) => {
338342 test ( '响应 id 应该与请求 id 匹配' , ( ) => {
339343 fc . assert (
340- fc . property ( fc . integer ( { min : 1 , max : 10000 } ) , ( requestId ) => {
344+ fc . property ( fc . integer ( { min : 1 , max : 10000 } ) , ( requestId : number ) => {
341345 const request = { id : requestId , method : 'Network.getResponseBody' }
342346 const response = { id : requestId , result : { } }
343347
@@ -353,7 +357,7 @@ describe('Property-Based Tests', () => {
353357 fc . integer ( { min : 1 , max : 10000 } ) ,
354358 fc . integer ( { min : - 32700 , max : - 32600 } ) ,
355359 fc . string ( ) ,
356- ( id , code , message ) => {
360+ ( id : number , code : number , message : string ) => {
357361 const errorResponse = {
358362 id,
359363 error : { code, message }
0 commit comments