From 2cb921937da1dfe95846771c2efb80ae5cff059b Mon Sep 17 00:00:00 2001 From: dirkluijk Date: Wed, 23 Oct 2024 00:05:44 +0200 Subject: [PATCH] fix: revert signature change --- src/index.ts | 6 +++--- tests/api.test.ts | 14 +++++++------- tests/node.test.ts | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1574ac6..e94c236 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ -import { vi } from 'vitest'; +import { vi as vitest } from 'vitest'; import type { Mock } from '@vitest/spy'; // type-definitions export type FetchMock = Mock & FetchMockObject; class FetchMockObject { - private readonly isMocking = vi.fn(always(true)); + private readonly isMocking = vitest.fn(always(true)); constructor( private mockedFetch: Mock, @@ -317,7 +317,7 @@ export interface MockResponse extends MockParams { } // factory -export default function createFetchMock(): FetchMock { +export default function createFetchMock(vi: typeof vitest): FetchMock { const isMocking = vi.fn(always(true)); const originalFetch = globalThis.fetch; diff --git a/tests/api.test.ts b/tests/api.test.ts index bddba4f..d0e44e4 100644 --- a/tests/api.test.ts +++ b/tests/api.test.ts @@ -3,7 +3,7 @@ import { APIRequest, APIRequest2, defaultRequestUri, request } from './api.js'; import createFetchMock, { type FetchMock, type MockResponse } from '../src/index.js'; describe('testing mockResponse', () => { - const fetch = createFetchMock(); + const fetch = createFetchMock(vi); beforeAll(() => { fetch.enableMocks(); @@ -102,7 +102,7 @@ describe('testing mockResponse', () => { }); describe('testing mockResponses', () => { - const fetch = createFetchMock(); + const fetch = createFetchMock(vi); beforeAll(() => { fetch.enableMocks(); @@ -135,7 +135,7 @@ describe('testing mockResponses', () => { }); describe('Mocking aborts', () => { - const fetch = createFetchMock(); + const fetch = createFetchMock(vi); beforeAll(() => { fetch.enableMocks(); @@ -184,7 +184,7 @@ describe('Mocking aborts', () => { }); describe('Mocking rejects', () => { - const fetch = createFetchMock(); + const fetch = createFetchMock(vi); beforeAll(() => { fetch.enableMocks(); @@ -205,7 +205,7 @@ describe('Mocking rejects', () => { }); describe('request', () => { - const fetch = createFetchMock(); + const fetch = createFetchMock(vi); beforeAll(() => { fetch.enableMocks(); @@ -383,7 +383,7 @@ describe('conditional mocking', () => { beforeEach(async () => { originalFetch = globalThis.fetch; globalThis.fetch = vi.fn(async () => Promise.resolve(new Response(realResponse))); - fetch = createFetchMock(); + fetch = createFetchMock(vi); await expectUnmocked(); @@ -749,7 +749,7 @@ describe('conditional mocking', () => { it('enable/disable', async () => { expect(vi.isMockFunction(globalThis.fetch)).toBe(false); - const fetch = createFetchMock(); + const fetch = createFetchMock(vi); expect(vi.isMockFunction(globalThis.fetch)).toBe(false); fetch.enableMocks(); expect(vi.isMockFunction(globalThis.fetch)).toBe(true); diff --git a/tests/node.test.ts b/tests/node.test.ts index 2d245ca..e7043eb 100644 --- a/tests/node.test.ts +++ b/tests/node.test.ts @@ -1,11 +1,11 @@ /** * @jest-environment node */ -import { it, expect } from 'vitest'; +import { it, expect, vi } from 'vitest'; import createFetchMock from '../src/index.js'; it('rejects with a dom exception', () => { - const mock = createFetchMock(); + const mock = createFetchMock(vi); mock.enableMocks(); mock.mockAbort(); expect(fetch('/')).rejects.toThrow(expect.any(DOMException));