File tree Expand file tree Collapse file tree
packages/astro/test/types Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { expectTypeOf } from 'expect-type' ;
22import { isInputError , defineAction } from '../../dist/actions/runtime/virtual/server.js' ;
33import { z } from '../../zod.mjs' ;
4+ import { describe , it } from 'node:test' ;
45
56const exampleAction = defineAction ( {
67 input : z . object ( {
@@ -11,16 +12,20 @@ const exampleAction = defineAction({
1112
1213const result = await exampleAction . safe ( { name : 'Alice' } ) ;
1314
14- // `isInputError` narrows unknown error types
15- try {
16- await exampleAction ( { name : 'Alice' } ) ;
17- } catch ( e ) {
18- if ( isInputError ( e ) ) {
19- expectTypeOf ( e . fields ) . toEqualTypeOf < Record < string , string [ ] | undefined > > ( ) ;
20- }
21- }
15+ describe ( 'isInputError' , ( ) => {
16+ it ( 'isInputError narrows unknown error types' , async ( ) => {
17+ try {
18+ await exampleAction ( { name : 'Alice' } ) ;
19+ } catch ( e ) {
20+ if ( isInputError ( e ) ) {
21+ expectTypeOf ( e . fields ) . toEqualTypeOf < Record < string , string [ ] | undefined > > ( ) ;
22+ }
23+ }
24+ } ) ;
2225
23- // `isInputError` preserves `fields` object type for ActionError objects
24- if ( isInputError ( result . error ) ) {
25- expectTypeOf ( result . error . fields ) . toEqualTypeOf < { name ?: string [ ] } > ( ) ;
26- }
26+ it ( '`isInputError` preserves `fields` object type for ActionError objects' , async ( ) => {
27+ if ( isInputError ( result . error ) ) {
28+ expectTypeOf ( result . error . fields ) . toEqualTypeOf < { name ?: string [ ] } > ( ) ;
29+ }
30+ } ) ;
31+ } ) ;
You can’t perform that action at this time.
0 commit comments