@@ -85,12 +85,38 @@ test.describe("loader in an app", async () => {
8585 ` ,
8686 "app/routes/return-response.tsx" : js `
8787 export let loader = () => {
88- return new Response('Partial', { status: 207 });
88+ return new Response('Partial', { status: 207, headers: { 'X-Foo': 'Bar'} });
8989 }
9090 ` ,
9191 "app/routes/throw-response.tsx" : js `
9292 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'} });
94120 }
95121 ` ,
96122 "app/routes/return-object.tsx" : js `
@@ -196,6 +222,7 @@ test.describe("loader in an app", async () => {
196222 let app = new PlaywrightFixture ( appFixture , page ) ;
197223 let res = await app . goto ( "/return-response" ) ;
198224 expect ( res . status ( ) ) . toBe ( 207 ) ;
225+ expect ( res . headers ( ) [ "x-foo" ] ) . toBe ( "Bar" ) ;
199226 expect ( await res . text ( ) ) . toEqual ( "Partial" ) ;
200227 } ) ;
201228
@@ -205,6 +232,45 @@ test.describe("loader in an app", async () => {
205232 let app = new PlaywrightFixture ( appFixture , page ) ;
206233 let res = await app . goto ( "/throw-response" ) ;
207234 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" ) ;
208274 expect ( await res . text ( ) ) . toEqual ( "Partial" ) ;
209275 } ) ;
210276
0 commit comments