@@ -252,35 +252,35 @@ We recommend to use the types provided by the parser utility. If you encounter a
252
252
253
253
## Testing your code
254
254
255
- When testing your handler with ** parser decorator** you need to use double assetion to bypass TypeScript type checking in your tests.
255
+ When testing your handler with [ ** parser decorator** ] ( #parse-events ) you need to use double assetion to bypass TypeScript type checking in your tests.
256
256
This is useful when you want to test the handler for invalid payloads or when you want to test the error handling.
257
257
If you are you use middy middleware, you don't need to do this.
258
258
259
259
=== "handlerDecorator.test.ts"
260
260
261
- ```typescript hl_lines="29 "
261
+ ```typescript hl_lines="26 "
262
262
--8<-- "examples/snippets/parser/unitTestDecorator.ts"
263
263
```
264
-
264
+
265
265
1. Use double assertion `as unknown as X` to bypass TypeScript type checking in your tests
266
266
267
267
=== "handlerDecorator.ts"
268
268
269
269
```typescript
270
- --8<-- "examples/snippets/parser/decorator .ts"
270
+ --8<-- "examples/snippets/parser/handlerDecorator .ts"
271
271
```
272
272
273
273
=== "schema.ts"
274
274
275
- ```typescript"
275
+ ```typescript
276
276
--8<-- "examples/snippets/parser/schema.ts"
277
277
```
278
278
279
279
This also works when using ` safeParse ` option.
280
280
281
281
=== "handlerSafeParse.test.ts"
282
282
283
- ```typescript hl_lines="24-32 38 48 "
283
+ ```typescript hl_lines="21-29 35 45 "
284
284
--8<-- "examples/snippets/parser/unitTestSafeParse.ts"
285
285
```
286
286
@@ -289,11 +289,11 @@ This also works when using `safeParse` option.
289
289
=== "handlerSafeParse.ts"
290
290
291
291
```typescript
292
- --8<-- "examples/snippets/parser/safeParseDecorator .ts"
292
+ --8<-- "examples/snippets/parser/handlerSafeParseDecorator .ts"
293
293
```
294
294
295
295
=== "schema.ts"
296
296
297
- ```typescript"
297
+ ```typescript
298
298
--8<-- "examples/snippets/parser/schema.ts"
299
299
```
0 commit comments