@@ -11,7 +11,7 @@ import type { Api } from "../src/types.ts";
1111
1212describe ( "REST API endpoint methods" , ( ) => {
1313 it ( "README example" , async ( ) => {
14- const mock = fetchMock . sandbox ( ) . post (
14+ const mock = fetchMock . createInstance ( ) . post (
1515 "path:/user/repos" ,
1616 { id : 1 } ,
1717 {
@@ -25,7 +25,7 @@ describe("REST API endpoint methods", () => {
2525 const octokit = new MyOctokit ( {
2626 auth : "secret123" ,
2727 request : {
28- fetch : mock ,
28+ fetch : mock . fetchHandler ,
2929 } ,
3030 } ) ;
3131
@@ -39,13 +39,13 @@ describe("REST API endpoint methods", () => {
3939
4040 it ( "Required preview header" , async ( ) => {
4141 const mock = fetchMock
42- . sandbox ( )
42+ . createInstance ( )
4343 . getOnce ( "path:/codes_of_conduct" , [ { key : "mit" } ] ) ;
4444
4545 const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
4646 const octokit = new MyOctokit ( {
4747 request : {
48- fetch : mock ,
48+ fetch : mock . fetchHandler ,
4949 } ,
5050 } ) ;
5151
@@ -56,24 +56,26 @@ describe("REST API endpoint methods", () => {
5656 } ) ;
5757
5858 it ( "octokit.rest.markdown.renderRaw()" , async ( ) => {
59- const mock = fetchMock . sandbox ( ) . postOnce (
60- "path:/markdown/raw" ,
59+ const mock = fetchMock . createInstance ( ) . postOnce (
60+ ( { url, options : { body } } ) => {
61+ if ( url === "https://api.github.com/markdown/raw" ) {
62+ expect ( body ) . toEqual ( "# Hello, world!" ) ;
63+ return true ;
64+ }
65+ return false ;
66+ } ,
6167 { ok : true } ,
6268 {
6369 headers : {
6470 "content-type" : "text/plain; charset=utf-8" ,
6571 } ,
66- matcher : ( _ , { body } ) => {
67- expect ( body ) . toEqual ( "# Hello, world!" ) ;
68- return true ;
69- } ,
7072 } ,
7173 ) ;
7274
7375 const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
7476 const octokit = new MyOctokit ( {
7577 request : {
76- fetch : mock ,
78+ fetch : mock . fetchHandler ,
7779 } ,
7880 } ) ;
7981
@@ -89,8 +91,18 @@ describe("REST API endpoint methods", () => {
8991 } ) ;
9092
9193 it ( "octokit.rest.repos.uploadReleaseAsset()" , async ( ) => {
92- const mock = fetchMock . sandbox ( ) . postOnce (
93- "https://uploads.github.com/repos/octocat/hello-world/releases/123/assets" ,
94+ const mock = fetchMock . createInstance ( ) . postOnce (
95+ ( { url, options : { body } } ) => {
96+ const path = new URL ( url ) ;
97+ if (
98+ `${ path . origin } ${ path . pathname } ` ===
99+ "https://uploads.github.com/repos/octocat/hello-world/releases/123/assets"
100+ ) {
101+ expect ( body ) . toEqual ( "test 1, 2" ) ;
102+ return true ;
103+ }
104+ return false ;
105+ } ,
94106 { ok : true } ,
95107 {
96108 headers : {
@@ -100,18 +112,14 @@ describe("REST API endpoint methods", () => {
100112 name : "test.txt" ,
101113 label : "test" ,
102114 } ,
103- matcher : ( _ , { body } ) => {
104- expect ( body ) . toEqual ( "test 1, 2" ) ;
105- return true ;
106- } ,
107115 } ,
108116 ) ;
109117
110118 const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
111119 const octokit = new MyOctokit ( {
112120 auth : "secret123" ,
113121 request : {
114- fetch : mock ,
122+ fetch : mock . fetchHandler ,
115123 } ,
116124 } ) ;
117125
@@ -135,7 +143,7 @@ describe("REST API endpoint methods", () => {
135143 } ) ;
136144
137145 it ( "octokit.rest.repos.addProtectedBranchRequiredStatusChecksContexts(): `contexts` option value is sent as request body without namespace" , async ( ) => {
138- const mock = fetchMock . sandbox ( ) . postOnce (
146+ const mock = fetchMock . createInstance ( ) . postOnce (
139147 "https://api.github.com/repos/octocat/hello-world/branches/latest/protection/required_status_checks/contexts" ,
140148 { ok : true } ,
141149 {
@@ -147,7 +155,7 @@ describe("REST API endpoint methods", () => {
147155 const octokit = new MyOctokit ( {
148156 auth : "secret123" ,
149157 request : {
150- fetch : mock ,
158+ fetch : mock . fetchHandler ,
151159 } ,
152160 } ) ;
153161
@@ -167,14 +175,14 @@ describe("REST API endpoint methods", () => {
167175
168176 it ( "octokit.rest.apps.listInstallations(): method without options (octokit/rest.js#818)" , async ( ) => {
169177 const mock = fetchMock
170- . sandbox ( )
178+ . createInstance ( )
171179 . getOnce ( "https://api.github.com/app/installations" , { ok : true } ) ;
172180
173181 const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
174182 const octokit = new MyOctokit ( {
175183 auth : "secret123" ,
176184 request : {
177- fetch : mock ,
185+ fetch : mock . fetchHandler ,
178186 } ,
179187 } ) ;
180188
@@ -186,7 +194,7 @@ describe("REST API endpoint methods", () => {
186194
187195 beforeEach ( ( ) => {
188196 const networkMock = fetchMock
189- . sandbox ( )
197+ . createInstance ( )
190198 . getOnce (
191199 "https://api.github.com/repos/octokit/plugin-rest-endpoint-methods/issues/1/labels" ,
192200 [ { name : "mocked from network" } ] ,
@@ -195,7 +203,7 @@ describe("REST API endpoint methods", () => {
195203 const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
196204 octokit = new MyOctokit ( {
197205 request : {
198- fetch : networkMock ,
206+ fetch : networkMock . fetchHandler ,
199207 } ,
200208 } ) ;
201209 } ) ;
@@ -278,7 +286,7 @@ describe("REST API endpoint methods", () => {
278286 // We will deprecate the `octokit.*` methods in future, but for now we just make sure they are set
279287
280288 it ( "legacyRestEndpointMethods" , async ( ) => {
281- const mock = fetchMock . sandbox ( ) . post (
289+ const mock = fetchMock . createInstance ( ) . post (
282290 "path:/user/repos" ,
283291 { id : 1 } ,
284292 {
@@ -292,7 +300,7 @@ describe("REST API endpoint methods", () => {
292300 const octokit = new MyOctokit ( {
293301 auth : "secret123" ,
294302 request : {
295- fetch : mock ,
303+ fetch : mock . fetchHandler ,
296304 } ,
297305 } ) ;
298306
0 commit comments