@@ -61,7 +61,7 @@ test.describe("loader in an app", async () => {
61
61
export default () => <div data-testid="redirect-destination">You made it!</div>
62
62
` ,
63
63
"app/routes/defer.tsx" : js `
64
- export let loader = () => ({ data: 'whatever' });
64
+ export let loader = () => ({ data: Promise.resolve( 'whatever') });
65
65
` ,
66
66
"app/routes/data[.]json.tsx" : js `
67
67
export let loader = () => Response.json({ hello: "world" });
@@ -101,6 +101,11 @@ test.describe("loader in an app", async () => {
101
101
return { hello: 'world' };
102
102
}
103
103
` ,
104
+ "app/routes/return-string.tsx" : js `
105
+ export let loader = () => {
106
+ return 'hello world';
107
+ }
108
+ ` ,
104
109
"app/routes/throw-object.tsx" : js `
105
110
export let loader = () => {
106
111
throw { but: 'why' };
@@ -207,9 +212,25 @@ test.describe("loader in an app", async () => {
207
212
expect ( await res . text ( ) ) . toEqual ( "Partial" ) ;
208
213
} ) ;
209
214
210
- // TODO: This test should work once we bring over the changes from
211
- // https://github.com/remix-run/remix/pull/9349 to the v7 branch
212
- test . skip ( "should handle objects returned from resource routes" , async ( {
215
+ test ( "should convert strings returned from resource routes to text responses" , async ( {
216
+ page,
217
+ } ) => {
218
+ let app = new PlaywrightFixture ( appFixture , page ) ;
219
+ let res = await app . goto ( "/return-string" ) ;
220
+ expect ( res . status ( ) ) . toBe ( 200 ) ;
221
+ expect ( await res . text ( ) ) . toEqual ( "hello world" ) ;
222
+ } ) ;
223
+
224
+ test ( "should convert non-strings returned from resource routes to JSON responses" , async ( {
225
+ page,
226
+ } ) => {
227
+ let app = new PlaywrightFixture ( appFixture , page ) ;
228
+ let res = await app . goto ( "/return-object" ) ;
229
+ expect ( res . status ( ) ) . toBe ( 200 ) ;
230
+ expect ( await res . json ( ) ) . toEqual ( { hello : "world" } ) ;
231
+ } ) ;
232
+
233
+ test ( "should handle objects returned from resource routes" , async ( {
213
234
page,
214
235
} ) => {
215
236
let app = new PlaywrightFixture ( appFixture , page ) ;
@@ -256,10 +277,8 @@ test.describe("loader in an app", async () => {
256
277
} ) => {
257
278
let app = new PlaywrightFixture ( appFixture , page ) ;
258
279
let res = await app . goto ( "/defer" ) ;
259
- expect ( res . status ( ) ) . toBe ( 500 ) ;
260
- expect ( await res . text ( ) ) . toMatch (
261
- "Error: Expected a Response to be returned from resource route handler"
262
- ) ;
280
+ expect ( res . status ( ) ) . toBe ( 200 ) ;
281
+ expect ( await res . json ( ) ) . toEqual ( { data : { } } ) ;
263
282
} ) ;
264
283
} ) ;
265
284
0 commit comments