@@ -2,13 +2,13 @@ import { headersToObject } from 'headers-polyfill'
22import { HttpResponse , http } from 'msw'
33
44export type Post = {
5- id : string
5+ id : number
66 title : string
77 body : string
88}
99
1010export const posts : Record < string , Post > = {
11- '1' : { id : '1' , title : 'hello' , body : 'extra body!' } ,
11+ 1 : { id : 1 , title : 'hello' , body : 'extra body!' } ,
1212}
1313
1414export const handlers = [
@@ -25,6 +25,7 @@ export const handlers = [
2525 } )
2626 }
2727 ) ,
28+
2829 http . post (
2930 'https://example.com/echo' ,
3031 async ( { request, cookies, params, requestId } ) => {
@@ -50,19 +51,25 @@ export const handlers = [
5051 } )
5152 }
5253 ) ,
54+
5355 http . get ( 'https://example.com/success' , ( ) =>
5456 HttpResponse . json ( { value : 'success' } )
5557 ) ,
58+
5659 http . post ( 'https://example.com/success' , ( ) =>
5760 HttpResponse . json ( { value : 'success' } )
5861 ) ,
62+
5963 http . get ( 'https://example.com/empty' , ( ) => new HttpResponse ( '' ) ) ,
64+
6065 http . get ( 'https://example.com/error' , ( ) =>
6166 HttpResponse . json ( { value : 'error' } , { status : 500 } )
6267 ) ,
68+
6369 http . post ( 'https://example.com/error' , ( ) =>
6470 HttpResponse . json ( { value : 'error' } , { status : 500 } )
6571 ) ,
72+
6673 http . get ( 'https://example.com/nonstandard-error' , ( ) =>
6774 HttpResponse . json (
6875 {
@@ -72,18 +79,22 @@ export const handlers = [
7279 { status : 200 }
7380 )
7481 ) ,
82+
7583 http . get ( 'https://example.com/mirror' , ( { params } ) =>
7684 HttpResponse . json ( params )
7785 ) ,
86+
7887 http . post ( 'https://example.com/mirror' , ( { params } ) =>
7988 HttpResponse . json ( params )
8089 ) ,
90+
8191 http . get ( 'https://example.com/posts/random' , ( ) => {
8292 // just simulate an api that returned a random ID
8393 const { id } = posts [ 1 ]
8494 return HttpResponse . json ( { id } )
8595 } ) ,
86- http . get < Post , any , Pick < Post , 'id' > > (
96+
97+ http . get < { id : string } , any , Pick < Post , 'id' > > (
8798 'https://example.com/post/:id' ,
8899 ( { params } ) => HttpResponse . json ( posts [ params . id ] )
89100 ) ,
0 commit comments