From 9fa6cdbab097a40c23879b03b31c2f832369c3a6 Mon Sep 17 00:00:00 2001 From: Marcelo Luiz Onhate Date: Thu, 1 Aug 2024 12:11:44 -0300 Subject: [PATCH] added test coverage for throw custom error --- test/exceptionshandling.test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/exceptionshandling.test.js diff --git a/test/exceptionshandling.test.js b/test/exceptionshandling.test.js new file mode 100644 index 00000000..ebf2d2fb --- /dev/null +++ b/test/exceptionshandling.test.js @@ -0,0 +1,30 @@ +import process from 'node:process'; +import dotenv from 'dotenv'; +import {describe, expect, it} from 'vitest'; +import {initializeClient} from './setup.js'; + +dotenv.config(); + +const username = process.env.ZENDESK_USERNAME; +const token = process.env.ZENDESK_TOKEN; + +describe('Zendesk Exceptions Handling', () => { + it('should throw an error for an invalid subdomain', async () => { + const error = new Error('My Custom Error'); + error.details = 'Custom Details'; + + const client = initializeClient({ + username, + token, + subdomain: 'any', + throwOriginalException: true, + transportConfig: { + transportFn() { + throw error; + }, + }, + }); + + await expect(() => client.users.me()).rejects.toThrowError(error); + }); +});