11import { jest } from "@jest/globals" ;
2- import { FetchError , Response } from "node-fetch" ;
3-
4- jest . unstable_mockModule ( "node-fetch" , ( ) => ( {
5- default : jest . fn ( ) ,
6- FetchError,
7- } ) ) ;
8-
92import {
103 ReplicateError ,
114 ReplicateRequestError ,
125 ReplicateResponseError ,
136} from "./errors.js" ;
147import Model from "./Model.js" ;
158import Prediction from "./Prediction.js" ;
16-
17- const { default : fetch } = await import ( "node-fetch" ) ;
18- const { default : ReplicateClient } = await import ( "./ReplicateClient.js" ) ;
9+ import ReplicateClient from "./ReplicateClient.js" ;
1910
2011let client ;
2112
@@ -170,7 +161,7 @@ describe("prediction()", () => {
170161describe ( "request()" , ( ) => {
171162 it ( "throws ReplicateRequestError on failed fetch" , async ( ) => {
172163 fetch . mockImplementation ( async ( ) => {
173- throw new FetchError ( "Something went wrong" ) ;
164+ throw new Error ( "Something went wrong" ) ;
174165 } ) ;
175166
176167 await expect (
@@ -179,18 +170,15 @@ describe("request()", () => {
179170 await expect (
180171 async ( ) => await client . request ( "GET /v1/predictions/testprediction" )
181172 ) . rejects . toThrowError (
182- "Failed to make request: method=GET, url=https://api.replicate.com/v1/predictions/testprediction, body=undefined"
173+ "Failed to make request: method=GET, url=https://api.replicate.com/v1/predictions/testprediction, body=undefined, error=Error: Something went wrong "
183174 ) ;
184175 } ) ;
185176
186177 it ( "throws ReplicateResponseError on error status" , async ( ) => {
187- fetch . mockImplementation (
188- async ( ) =>
189- new Response ( '{"status":403,"details":"Something went wrong"}' , {
190- status : 403 ,
191- statusText : "Unauthorized" ,
192- } )
193- ) ;
178+ fetch . mockResponse ( '{"status":403,"details":"Something went wrong"}' , {
179+ status : 403 ,
180+ statusText : "Unauthorized" ,
181+ } ) ;
194182
195183 await expect (
196184 async ( ) => await client . request ( "GET /v1/predictions/testprediction" )
0 commit comments