@@ -174,7 +174,7 @@ describe('Astro Actions', () => {
174
174
it ( 'Respects user middleware' , async ( ) => {
175
175
const formData = new FormData ( ) ;
176
176
formData . append ( '_astroAction' , '/_actions/getUser' ) ;
177
- const req = new Request ( 'http://example.com/middleware ' , {
177
+ const req = new Request ( 'http://example.com/user ' , {
178
178
method : 'POST' ,
179
179
body : formData ,
180
180
} ) ;
@@ -185,5 +185,22 @@ describe('Astro Actions', () => {
185
185
let $ = cheerio . load ( html ) ;
186
186
assert . equal ( $ ( '#user' ) . text ( ) , 'Houston' ) ;
187
187
} ) ;
188
+
189
+ it ( 'Respects custom errors' , async ( ) => {
190
+ const formData = new FormData ( ) ;
191
+ formData . append ( '_astroAction' , '/_actions/getUserOrThrow' ) ;
192
+ const req = new Request ( 'http://example.com/user-or-throw' , {
193
+ method : 'POST' ,
194
+ body : formData ,
195
+ } ) ;
196
+ const res = await app . render ( req ) ;
197
+ assert . equal ( res . ok , false ) ;
198
+ assert . equal ( res . status , 401 ) ;
199
+
200
+ const html = await res . text ( ) ;
201
+ let $ = cheerio . load ( html ) ;
202
+ assert . equal ( $ ( '#error-message' ) . text ( ) , 'Not logged in' ) ;
203
+ assert . equal ( $ ( '#error-code' ) . text ( ) , 'UNAUTHORIZED' ) ;
204
+ } )
188
205
} ) ;
189
206
} ) ;
0 commit comments