From c73067d21bcdd48e2e67cae6a3b87700bfa986dc Mon Sep 17 00:00:00 2001 From: Chuck MANCHUCK Reeves Date: Tue, 18 Jun 2024 10:08:45 -0400 Subject: [PATCH] test: adding error testing and a nock clean --- testHelpers/vonageTest.ts | 41 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/testHelpers/vonageTest.ts b/testHelpers/vonageTest.ts index 9bf5cea7..de861fc7 100644 --- a/testHelpers/vonageTest.ts +++ b/testHelpers/vonageTest.ts @@ -10,7 +10,14 @@ import { getResults } from './getResults'; */ export const VonageTest = (testDataSets: TestTuple[]) => { describe.each(testDataSets)('$label', ({ tests }) => { - test.each>(tests)( + afterEach(function () { + nock.cleanAll(); + }); + + const successTests = tests.filter(({ error }) => !error); + const failureTests = tests.filter(({ error }) => !!error); + + test.each>(successTests)( 'Can $label', async ({ baseUrl, @@ -42,8 +49,38 @@ export const VonageTest = (testDataSets: TestTuple[]) => { expect(results).toEqual(expected); expect(nock.isDone()).toBeTruthy(); + }, + ); + + if (failureTests.length < 1) { + return; + } + + test.each(failureTests)( + 'Will throw $label', + async ({ + baseUrl, + reqHeaders, + requests, + responses, + client, + clientMethod, + parameters, + }) => { + const scope = nock(baseUrl, { + reqheaders: reqHeaders, + }); + + requests.forEach((request, index) => { + (scope as nock.Scope) + .intercept(...request) + .reply(...responses[index]); + }); + + await expect(() => client[clientMethod](...parameters)).rejects.toThrow( + error, + ); - expect(results).toEqual(expected); expect(nock.isDone()).toBeTruthy(); }, );