19
19
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
*/
21
21
22
- import { describe , it , expect } from "@jest/globals" ;
22
+ import { jest , describe , it , expect } from "@jest/globals" ;
23
+ import type { Mock } from "jest-mock" ;
24
+
23
25
jest . mock ( "../fetcher.ts" , ( ) => ( {
24
26
fetch : jest . fn ( ) . mockImplementation ( ( ) =>
25
27
Promise . resolve (
@@ -167,16 +169,15 @@ describe("getSolidDataset", () => {
167
169
} ) ;
168
170
169
171
it ( "does not provide an IRI to an ACL resource if not provided one by the server" , async ( ) => {
170
- const mockFetch = jest . fn ( window . fetch ) . mockResolvedValue (
171
- new Response ( undefined , {
172
- headers : {
173
- Link : '<arbitrary-resource>; rel="not-acl"' ,
174
- } ,
175
- url : "https://arbitrary.pod" ,
176
- // We need the type assertion because in non-mock situations,
177
- // you cannot set the URL manually:
178
- } as ResponseInit )
179
- ) ;
172
+ const mockResponse = new Response ( undefined , {
173
+ headers : {
174
+ Link : '<arbitrary-resource>; rel="not-acl"' ,
175
+ } ,
176
+ url : "https://arbitrary.pod" ,
177
+ // We need the type assertion because in non-mock situations,
178
+ // you cannot set the URL manually:
179
+ } as ResponseInit ) ;
180
+ const mockFetch = jest . fn ( window . fetch ) . mockResolvedValue ( mockResponse ) ;
180
181
181
182
const solidDataset = await getSolidDataset (
182
183
"https://some.pod/container/resource" ,
@@ -349,7 +350,7 @@ describe("getSolidDatasetWithAcl", () => {
349
350
return Promise . resolve (
350
351
mockResponse ( undefined , {
351
352
headers : headers ,
352
- url : url ,
353
+ url : url as string ,
353
354
} )
354
355
) ;
355
356
} ) ;
@@ -1232,16 +1233,15 @@ describe("createContainerAt", () => {
1232
1233
} ) ;
1233
1234
1234
1235
it ( "does not provide an IRI to an ACL resource if not provided one by the server" , async ( ) => {
1235
- const mockFetch = jest . fn ( window . fetch ) . mockResolvedValue (
1236
- new Response ( undefined , {
1237
- headers : {
1238
- Link : '<arbitrary-resource>; rel="not-acl"' ,
1239
- } ,
1240
- url : "https://arbitrary.pod" ,
1241
- // We need the type assertion because in non-mock situations,
1242
- // you cannot set the URL manually:
1243
- } as ResponseInit )
1244
- ) ;
1236
+ const mockResponse = new Response ( undefined , {
1237
+ headers : {
1238
+ Link : '<arbitrary-resource>; rel="not-acl"' ,
1239
+ } ,
1240
+ url : "https://arbitrary.pod" ,
1241
+ // We need the type assertion because in non-mock situations,
1242
+ // you cannot set the URL manually:
1243
+ } as ResponseInit ) ;
1244
+ const mockFetch = jest . fn ( window . fetch ) . mockResolvedValue ( mockResponse ) ;
1245
1245
1246
1246
const solidDataset = await createContainerAt (
1247
1247
"https://some.pod/container/" ,
@@ -1565,9 +1565,9 @@ describe("createContainerAt", () => {
1565
1565
} ) ;
1566
1566
1567
1567
describe ( "saveSolidDatasetInContainer" , ( ) => {
1568
- type MockFetch = jest . Mock <
1568
+ type MockFetch = Mock <
1569
1569
ReturnType < typeof window . fetch > ,
1570
- [ RequestInfo , RequestInit ? ]
1570
+ Parameters < typeof window . fetch >
1571
1571
> ;
1572
1572
function setMockOnFetch (
1573
1573
fetch : MockFetch ,
@@ -1926,7 +1926,7 @@ describe("saveSolidDatasetInContainer", () => {
1926
1926
} ) ;
1927
1927
1928
1928
describe ( "createContainerInContainer" , ( ) => {
1929
- type MockFetch = jest . Mock <
1929
+ type MockFetch = Mock <
1930
1930
ReturnType < typeof window . fetch > ,
1931
1931
[ RequestInfo , RequestInit ?]
1932
1932
> ;
@@ -1953,10 +1953,7 @@ describe("createContainerInContainer", () => {
1953
1953
1954
1954
it ( "calls the included fetcher by default" , async ( ) => {
1955
1955
const mockedFetcher = jest . requireMock ( "../fetcher.ts" ) as {
1956
- fetch : jest . Mock <
1957
- ReturnType < typeof window . fetch > ,
1958
- [ RequestInfo , RequestInit ?]
1959
- > ;
1956
+ fetch : MockFetch ;
1960
1957
} ;
1961
1958
mockedFetcher . fetch = setMockOnFetch ( mockedFetcher . fetch ) ;
1962
1959
0 commit comments