1
+ import { setTimeout } from 'node:timers/promises' ;
1
2
import { describe , expect , it } from 'vitest' ;
2
3
import { validator } from '../../src/decorator.js' ;
3
4
import { SchemaValidationError } from '../../src/errors.js' ;
@@ -21,11 +22,12 @@ const outboundSchema = {
21
22
} ;
22
23
23
24
describe ( 'Decorator: validator' , ( ) => {
24
- it ( 'should validate inbound and outbound successfully' , async ( ) => {
25
+ it ( 'validates both inbound and outbound successfully' , async ( ) => {
25
26
// Prepare
26
27
class TestClass {
27
28
@validator ( { inboundSchema, outboundSchema } )
28
29
async multiply ( input : { value : number } ) : Promise < { result : number } > {
30
+ await setTimeout ( 1 ) ; // simulate some processing time
29
31
return { result : input . value * 2 } ;
30
32
}
31
33
}
@@ -39,11 +41,12 @@ describe('Decorator: validator', () => {
39
41
expect ( output ) . toEqual ( { result : 10 } ) ;
40
42
} ) ;
41
43
42
- it ( 'should throw error on inbound validation failure' , async ( ) => {
44
+ it ( 'throws an error on inbound validation failure' , async ( ) => {
43
45
// Prepare
44
46
class TestClass {
45
47
@validator ( { inboundSchema, outboundSchema } )
46
48
async multiply ( input : { value : number } ) : Promise < { result : number } > {
49
+ await setTimeout ( 1 ) ; // simulate some processing time
47
50
return { result : input . value * 2 } ;
48
51
}
49
52
}
@@ -58,11 +61,12 @@ describe('Decorator: validator', () => {
58
61
) ;
59
62
} ) ;
60
63
61
- it ( 'should throw error on outbound validation failure' , async ( ) => {
64
+ it ( 'throws an error on outbound validation failure' , async ( ) => {
62
65
// Prepare
63
66
class TestClassInvalid {
64
67
@validator ( { inboundSchema, outboundSchema } )
65
68
async multiply ( _input : { value : number } ) {
69
+ await setTimeout ( 1 ) ; // simulate some processing time
66
70
return { result : 'invalid' } ;
67
71
}
68
72
}
@@ -74,11 +78,12 @@ describe('Decorator: validator', () => {
74
78
) ;
75
79
} ) ;
76
80
77
- it ( 'should no-op when no schemas are provided' , async ( ) => {
81
+ it ( 'results in a no-op when no schemas are provided' , async ( ) => {
78
82
// Prepare
79
83
class TestClassNoOp {
80
84
@validator ( { } )
81
85
async echo ( input : unknown ) : Promise < unknown > {
86
+ await setTimeout ( 1 ) ; // simulate some processing time
82
87
return input ;
83
88
}
84
89
}
@@ -92,11 +97,12 @@ describe('Decorator: validator', () => {
92
97
expect ( result ) . toEqual ( data ) ;
93
98
} ) ;
94
99
95
- it ( 'should validate inbound only' , async ( ) => {
100
+ it ( 'validates the inbound schema only' , async ( ) => {
96
101
// Prepare
97
102
class TestClassInbound {
98
103
@validator ( { inboundSchema } )
99
104
async process ( input : { value : number } ) : Promise < { data : string } > {
105
+ await setTimeout ( 1 ) ; // simulate some processing time
100
106
return { data : JSON . stringify ( input ) } ;
101
107
}
102
108
}
@@ -110,11 +116,12 @@ describe('Decorator: validator', () => {
110
116
expect ( output ) . toEqual ( { data : JSON . stringify ( input ) } ) ;
111
117
} ) ;
112
118
113
- it ( 'should validate outbound only' , async ( ) => {
119
+ it ( 'validates the outbound schema only' , async ( ) => {
114
120
// Prepare
115
121
class TestClassOutbound {
116
122
@validator ( { outboundSchema } )
117
123
async process ( _input : { text : string } ) : Promise < { result : number } > {
124
+ await setTimeout ( 1 ) ; // simulate some processing time
118
125
return { result : 42 } ;
119
126
}
120
127
}
0 commit comments