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(); }, );