1
- import fetchMock from "fetch-mock" ;
1
+ import fetchMock , { FetchMock } from "fetch-mock" ;
2
2
3
3
import { describe , it , expect } from "vitest" ;
4
4
import { request } from "../src/index.ts" ;
@@ -9,19 +9,18 @@ describe("endpoint.defaults()", () => {
9
9
} ) ;
10
10
11
11
it ( "README example" , ( ) => {
12
- const mock = fetchMock
13
- . sandbox ( )
14
- . mock (
15
- "https://github-enterprise.acme-inc.com/api/v3/orgs/my-project/repos?per_page=100" ,
16
- [ ] ,
17
- {
18
- headers : {
19
- accept : "application/vnd.github.v3+json" ,
20
- authorization : "token 0000000000000000000000000000000000000001" ,
21
- "user-agent" : "myApp/1.2.3" ,
22
- } ,
12
+ const mock = fetchMock . createInstance ( ) ;
13
+ mock . get (
14
+ "https://github-enterprise.acme-inc.com/api/v3/orgs/my-project/repos?per_page=100" ,
15
+ [ ] ,
16
+ {
17
+ headers : {
18
+ accept : "application/vnd.github.v3+json" ,
19
+ authorization : "token 0000000000000000000000000000000000000001" ,
20
+ "user-agent" : "myApp/1.2.3" ,
23
21
} ,
24
- ) ;
22
+ } ,
23
+ ) ;
25
24
26
25
const myRequest = request . defaults ( {
27
26
baseUrl : "https://github-enterprise.acme-inc.com/api/v3" ,
@@ -32,7 +31,7 @@ describe("endpoint.defaults()", () => {
32
31
org : "my-project" ,
33
32
per_page : 100 ,
34
33
request : {
35
- fetch : mock ,
34
+ fetch : mock . fetchHandler ,
36
35
} ,
37
36
} ) ;
38
37
@@ -42,19 +41,18 @@ describe("endpoint.defaults()", () => {
42
41
} ) ;
43
42
44
43
it ( "repeated defaults" , ( ) => {
45
- const mock = fetchMock
46
- . sandbox ( )
47
- . get (
48
- "https://github-enterprise.acme-inc.com/api/v3/orgs/my-project/repos" ,
49
- [ ] ,
50
- {
51
- headers : {
52
- accept : "application/vnd.github.v3.raw+json" ,
53
- authorization : "token 0000000000000000000000000000000000000001" ,
54
- "user-agent" : "myApp/1.2.3" ,
55
- } ,
44
+ const mock = fetchMock . createInstance ( ) ;
45
+ mock . get (
46
+ "https://github-enterprise.acme-inc.com/api/v3/orgs/my-project/repos" ,
47
+ [ ] ,
48
+ {
49
+ headers : {
50
+ accept : "application/vnd.github.v3.raw+json" ,
51
+ authorization : "token 0000000000000000000000000000000000000001" ,
52
+ "user-agent" : "myApp/1.2.3" ,
56
53
} ,
57
- ) ;
54
+ } ,
55
+ ) ;
58
56
59
57
const myProjectRequest = request . defaults ( {
60
58
baseUrl : "https://github-enterprise.acme-inc.com/api/v3" ,
@@ -66,7 +64,7 @@ describe("endpoint.defaults()", () => {
66
64
} ,
67
65
org : "my-project" ,
68
66
request : {
69
- fetch : mock ,
67
+ fetch : mock . fetchHandler ,
70
68
} ,
71
69
} ) ;
72
70
const myProjectRequestWithAuth = myProjectRequest . defaults ( {
0 commit comments