diff --git a/test/management/token-provider-middleware.test.ts b/test/management/token-provider-middleware.test.ts index 78d6ed9f1..9a2eb3b9d 100644 --- a/test/management/token-provider-middleware.test.ts +++ b/test/management/token-provider-middleware.test.ts @@ -1,11 +1,15 @@ import nock from 'nock'; import { jest } from '@jest/globals'; -import { RequestOpts, InitOverrideFunction } from '../../src/lib/index.js'; +import { RequestOpts, InitOverrideFunction, FetchAPI } from '../../src/lib/index.js'; import { BaseAPI } from '../../src/lib/runtime.js'; import { TokenProviderMiddleware } from '../../src/management/token-provider-middleware.js'; const domain = 'test-domain.auth0.com'; +const customFetch = jest + .fn() + .mockImplementation((url: URL | RequestInfo, init?: RequestInit) => fetch(url, init)); + const opts = { baseUrl: `https://${domain}`, clientId: 'test-client-id', @@ -14,6 +18,7 @@ const opts = { parseError: async (response: Response) => { return new Error(`${response.status}`); }, + fetch: customFetch, }; export class TestClient extends BaseAPI { @@ -87,4 +92,11 @@ describe('TokenProviderMiddleware', () => { }) ); }); + + it('should use custom fetch', async () => { + await expect( + clientSecretClient.testRequest({ path: '/foo', method: 'GET' }) + ).resolves.toMatchObject({}); + expect(customFetch).toHaveBeenCalled(); + }); });