Skip to content

Commit

Permalink
fix: revert signature change
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkluijk committed Oct 22, 2024
1 parent 39d8891 commit 2cb9219
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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<typeof global.fetch> & FetchMockObject;

class FetchMockObject {
private readonly isMocking = vi.fn(always(true));
private readonly isMocking = vitest.fn(always(true));

constructor(
private mockedFetch: Mock<typeof global.fetch>,
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('testing mockResponse', () => {
});

describe('testing mockResponses', () => {
const fetch = createFetchMock();
const fetch = createFetchMock(vi);

beforeAll(() => {
fetch.enableMocks();
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('testing mockResponses', () => {
});

describe('Mocking aborts', () => {
const fetch = createFetchMock();
const fetch = createFetchMock(vi);

beforeAll(() => {
fetch.enableMocks();
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('Mocking aborts', () => {
});

describe('Mocking rejects', () => {
const fetch = createFetchMock();
const fetch = createFetchMock(vi);

beforeAll(() => {
fetch.enableMocks();
Expand All @@ -205,7 +205,7 @@ describe('Mocking rejects', () => {
});

describe('request', () => {
const fetch = createFetchMock();
const fetch = createFetchMock(vi);

beforeAll(() => {
fetch.enableMocks();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/node.test.ts
Original file line number Diff line number Diff line change
@@ -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));
Expand Down

0 comments on commit 2cb9219

Please sign in to comment.