From 81447b8e84947ae29b2073ce1013c9147d5a88f1 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Thu, 21 Sep 2023 06:21:26 -0700 Subject: [PATCH 1/2] Change expectation to hasAssertions for exception handling --- index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.test.ts b/index.test.ts index fb65f29d..af0e45d2 100644 --- a/index.test.ts +++ b/index.test.ts @@ -188,7 +188,7 @@ describe('Replicate client', () => { }, { "Content-Type": "application/json" }) try { - expect.assertions(2); + expect.hasAssertions(); await client.predictions.create({ version: '5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa', From 1f828c625a28ce24a6669bfaa1434b0dd6ce66b0 Mon Sep 17 00:00:00 2001 From: Mattt Zmuda Date: Thu, 21 Sep 2023 06:35:22 -0700 Subject: [PATCH 2/2] Disable network access and warn on unmatched mocks --- index.test.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/index.test.ts b/index.test.ts index af0e45d2..a560da18 100644 --- a/index.test.ts +++ b/index.test.ts @@ -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', () => {