@@ -85,12 +85,38 @@ test.describe("loader in an app", async () => {
85
85
` ,
86
86
"app/routes/return-response.tsx" : js `
87
87
export let loader = () => {
88
- return new Response('Partial', { status: 207 });
88
+ return new Response('Partial', { status: 207, headers: { 'X-Foo': 'Bar'} });
89
89
}
90
90
` ,
91
91
"app/routes/throw-response.tsx" : js `
92
92
export let loader = () => {
93
- throw new Response('Partial', { status: 207 });
93
+ throw new Response('Partial', { status: 207, headers: { 'X-Foo': 'Bar' } });
94
+ }
95
+ ` ,
96
+ "app/routes/return-data.tsx" : js `
97
+ import { data } from "react-router";
98
+ export let loader = () => {
99
+ return data('Partial', { status: 207, headers: { 'X-Foo': 'Bar'} });
100
+ }
101
+ ` ,
102
+ "app/routes/throw-data.tsx" : js `
103
+ import { data } from "react-router";
104
+ export let loader = () => {
105
+ throw data('Partial', { status: 207, headers: { 'X-Foo': 'Bar'} });
106
+ }
107
+ ` ,
108
+ "app/routes/return-data-through-middleware.tsx" : js `
109
+ import { data } from "react-router";
110
+ export const unstable_middleware = [(_, next) => next()]
111
+ export let loader = () => {
112
+ return data('Partial', { status: 207, headers: { 'X-Foo': 'Bar'} });
113
+ }
114
+ ` ,
115
+ "app/routes/throw-data-through-middleware.tsx" : js `
116
+ import { data } from "react-router";
117
+ export const unstable_middleware = [(_, next) => next()]
118
+ export let loader = () => {
119
+ throw data('Partial', { status: 207, headers: { 'X-Foo': 'Bar'} });
94
120
}
95
121
` ,
96
122
"app/routes/return-object.tsx" : js `
@@ -196,6 +222,7 @@ test.describe("loader in an app", async () => {
196
222
let app = new PlaywrightFixture ( appFixture , page ) ;
197
223
let res = await app . goto ( "/return-response" ) ;
198
224
expect ( res . status ( ) ) . toBe ( 207 ) ;
225
+ expect ( res . headers ( ) [ "x-foo" ] ) . toBe ( "Bar" ) ;
199
226
expect ( await res . text ( ) ) . toEqual ( "Partial" ) ;
200
227
} ) ;
201
228
@@ -205,6 +232,45 @@ test.describe("loader in an app", async () => {
205
232
let app = new PlaywrightFixture ( appFixture , page ) ;
206
233
let res = await app . goto ( "/throw-response" ) ;
207
234
expect ( res . status ( ) ) . toBe ( 207 ) ;
235
+ expect ( res . headers ( ) [ "x-foo" ] ) . toBe ( "Bar" ) ;
236
+ expect ( await res . text ( ) ) . toEqual ( "Partial" ) ;
237
+ } ) ;
238
+
239
+ test ( "should handle data() returned from resource routes" , async ( {
240
+ page,
241
+ } ) => {
242
+ let app = new PlaywrightFixture ( appFixture , page ) ;
243
+ let res = await app . goto ( "/return-data" ) ;
244
+ expect ( res . status ( ) ) . toBe ( 207 ) ;
245
+ expect ( res . headers ( ) [ "x-foo" ] ) . toBe ( "Bar" ) ;
246
+ expect ( await res . text ( ) ) . toEqual ( "Partial" ) ;
247
+ } ) ;
248
+
249
+ test ( "should handle data() thrown from resource routes" , async ( { page } ) => {
250
+ let app = new PlaywrightFixture ( appFixture , page ) ;
251
+ let res = await app . goto ( "/throw-data" ) ;
252
+ expect ( res . status ( ) ) . toBe ( 207 ) ;
253
+ expect ( res . headers ( ) [ "x-foo" ] ) . toBe ( "Bar" ) ;
254
+ expect ( await res . text ( ) ) . toEqual ( "Partial" ) ;
255
+ } ) ;
256
+
257
+ test ( "should handle data() returned from resource routes through middleware" , async ( {
258
+ page,
259
+ } ) => {
260
+ let app = new PlaywrightFixture ( appFixture , page ) ;
261
+ let res = await app . goto ( "/return-data-through-middleware" ) ;
262
+ expect ( res . status ( ) ) . toBe ( 207 ) ;
263
+ expect ( res . headers ( ) [ "x-foo" ] ) . toBe ( "Bar" ) ;
264
+ expect ( await res . text ( ) ) . toEqual ( "Partial" ) ;
265
+ } ) ;
266
+
267
+ test ( "should handle data() thrown from resource routes through middleware" , async ( {
268
+ page,
269
+ } ) => {
270
+ let app = new PlaywrightFixture ( appFixture , page ) ;
271
+ let res = await app . goto ( "/throw-data-through-middleware" ) ;
272
+ expect ( res . status ( ) ) . toBe ( 207 ) ;
273
+ expect ( res . headers ( ) [ "x-foo" ] ) . toBe ( "Bar" ) ;
208
274
expect ( await res . text ( ) ) . toEqual ( "Partial" ) ;
209
275
} ) ;
210
276
0 commit comments