@@ -102,8 +102,8 @@ const db = factory({
102102 user: {
103103 id: primaryKey (String ),
104104 firstName: String ,
105- age: Number
106- }
105+ age: Number ,
106+ },
107107})
108108```
109109
@@ -1159,7 +1159,7 @@ To gain more control over the mocks and implement more complex mocking scenarios
11591159Take a look at how you can create an entity based on the user's authentication status in a test:
11601160
11611161``` js
1162- import { rest } from ' msw'
1162+ import { http , HttpResponse } from ' msw'
11631163import { setupServer } from ' msw/node'
11641164import { factory , primaryKey } from ' @mswjs/data'
11651165
@@ -1171,17 +1171,17 @@ const db = factory({
11711171})
11721172
11731173const handlers = [
1174- rest .post (' /post' , (req , res , cxt ) => {
1174+ http .post (' /post' , (req , res , cxt ) => {
11751175 // Only authenticated users can create new posts.
11761176 if (req .headers .get (' authorization' ) === ' Bearer AUTH_TOKEN' ) {
1177- return res ( ctx . status ( 403 ) )
1177+ return new HttpResponse ( null , { status: 403 } )
11781178 }
11791179
11801180 // Create a new entity for the "post" model.
11811181 const newPost = db .post .create (req .body )
11821182
11831183 // Respond with a mocked response.
1184- return res ( ctx . status ( 201 ), ctx . json ({ post: newPost }) )
1184+ return HttpResponse . json ({ post: newPost }, { status : 201 } )
11851185 }),
11861186]
11871187
0 commit comments