@@ -21,29 +21,29 @@ const outboundSchema = {
21
21
} ;
22
22
23
23
describe ( 'Decorator: validator' , ( ) => {
24
- it ( 'should validate inbound and outbound successfully' , async ( ) => {
24
+ it ( 'should validate inbound and outbound successfully' , ( ) => {
25
25
// Prepare
26
26
class TestClass {
27
27
@validator ( { inboundSchema, outboundSchema } )
28
- async multiply ( input : { value : number } ) : Promise < { result : number } > {
28
+ multiply ( input : { value : number } ) : { result : number } {
29
29
return { result : input . value * 2 } ;
30
30
}
31
31
}
32
32
const instance = new TestClass ( ) ;
33
33
const input = { value : 5 } ;
34
34
35
35
// Act
36
- const output = await instance . multiply ( input ) ;
36
+ const output = instance . multiply ( input ) ;
37
37
38
38
// Assess
39
39
expect ( output ) . toEqual ( { result : 10 } ) ;
40
40
} ) ;
41
41
42
- it ( 'should throw error on inbound validation failure' , async ( ) => {
42
+ it ( 'should throw error on inbound validation failure' , ( ) => {
43
43
// Prepare
44
44
class TestClass {
45
45
@validator ( { inboundSchema, outboundSchema } )
46
- async multiply ( input : { value : number } ) : Promise < { result : number } > {
46
+ multiply ( input : { value : number } ) : { result : number } {
47
47
return { result : input . value * 2 } ;
48
48
}
49
49
}
@@ -53,76 +53,72 @@ describe('Decorator: validator', () => {
53
53
} ;
54
54
55
55
// Act & Assess
56
- await expect ( instance . multiply ( invalidInput ) ) . rejects . toThrow (
57
- SchemaValidationError
58
- ) ;
56
+ expect ( instance . multiply ( invalidInput ) ) . toThrow ( SchemaValidationError ) ;
59
57
} ) ;
60
58
61
- it ( 'should throw error on outbound validation failure' , async ( ) => {
59
+ it ( 'should throw error on outbound validation failure' , ( ) => {
62
60
// Prepare
63
61
class TestClassInvalid {
64
62
@validator ( { inboundSchema, outboundSchema } )
65
- async multiply ( _input : { value : number } ) {
63
+ multiply ( _input : { value : number } ) {
66
64
return { result : 'invalid' } ;
67
65
}
68
66
}
69
67
const instance = new TestClassInvalid ( ) ;
70
68
71
69
// Act & Assess
72
- await expect ( instance . multiply ( { value : 5 } ) ) . rejects . toThrow (
73
- SchemaValidationError
74
- ) ;
70
+ expect ( instance . multiply ( { value : 5 } ) ) . toThrow ( SchemaValidationError ) ;
75
71
} ) ;
76
72
77
- it ( 'should no-op when no schemas are provided' , async ( ) => {
73
+ it ( 'should no-op when no schemas are provided' , ( ) => {
78
74
// Prepare
79
75
class TestClassNoOp {
80
76
@validator ( { } )
81
- async echo ( input : unknown ) : Promise < unknown > {
77
+ echo ( input : unknown ) : unknown {
82
78
return input ;
83
79
}
84
80
}
85
81
const instance = new TestClassNoOp ( ) ;
86
82
const data = { foo : 'bar' } ;
87
83
88
84
// Act
89
- const result = await instance . echo ( data ) ;
85
+ const result = instance . echo ( data ) ;
90
86
91
87
// Assess
92
88
expect ( result ) . toEqual ( data ) ;
93
89
} ) ;
94
90
95
- it ( 'should validate inbound only' , async ( ) => {
91
+ it ( 'should validate inbound only' , ( ) => {
96
92
// Prepare
97
93
class TestClassInbound {
98
94
@validator ( { inboundSchema } )
99
- async process ( input : { value : number } ) : Promise < { data : string } > {
95
+ process ( input : { value : number } ) : { data : string } {
100
96
return { data : JSON . stringify ( input ) } ;
101
97
}
102
98
}
103
99
const instance = new TestClassInbound ( ) ;
104
100
const input = { value : 10 } ;
105
101
106
102
// Act
107
- const output = await instance . process ( input ) ;
103
+ const output = instance . process ( input ) ;
108
104
109
105
// Assess
110
106
expect ( output ) . toEqual ( { data : JSON . stringify ( input ) } ) ;
111
107
} ) ;
112
108
113
- it ( 'should validate outbound only' , async ( ) => {
109
+ it ( 'should validate outbound only' , ( ) => {
114
110
// Prepare
115
111
class TestClassOutbound {
116
112
@validator ( { outboundSchema } )
117
- async process ( _input : { text : string } ) : Promise < { result : number } > {
113
+ process ( _input : { text : string } ) : { result : number } {
118
114
return { result : 42 } ;
119
115
}
120
116
}
121
117
const instance = new TestClassOutbound ( ) ;
122
118
const input = { text : 'hello' } ;
123
119
124
120
// Act
125
- const output = await instance . process ( input ) ;
121
+ const output = instance . process ( input ) ;
126
122
127
123
// Assess
128
124
expect ( output ) . toEqual ( { result : 42 } ) ;
0 commit comments