Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@ import Replicate, { ApiError, Prediction } from 'replicate';
import nock from 'nock';
import fetch from 'cross-fetch';

describe('Replicate client', () => {
let client: Replicate;
let client: Replicate;
const BASE_URL = 'https://api.replicate.com/v1';

nock.disableNetConnect();

const BASE_URL = 'https://api.replicate.com/v1';
describe('Replicate client', () => {
let unmatched: Object[] = [];
const handleNoMatch = (req: unknown, options: any, body: string) =>
unmatched.push({ req, options, body });

beforeEach(() => {
client = new Replicate({ auth: 'test-token' });
client.fetch = fetch;

unmatched = [];
nock.emitter.on("no match", handleNoMatch);
});

afterEach(() => {
nock.emitter.off("no match", handleNoMatch);
expect(unmatched).toStrictEqual([]);

nock.abortPendingRequests();
nock.cleanAll();
});

describe('constructor', () => {
Expand Down Expand Up @@ -188,7 +204,7 @@ describe('Replicate client', () => {
}, { "Content-Type": "application/json" })

try {
expect.assertions(2);
expect.hasAssertions();

await client.predictions.create({
version: '5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa',
Expand Down