Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/features/votes/internal_clients/vote_grade.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect, beforeEach, afterEach } from 'vitest';
import { describe, test, expect, beforeEach, afterEach, vi } from 'vitest';
import nock from 'nock';

import { TaskGrade } from '$lib/types/task';
Expand All @@ -22,6 +22,7 @@ beforeEach(() => {
});

afterEach(() => {
vi.restoreAllMocks();
nock.cleanAll();
// Restore original location to prevent test state leak
if (originalLocation !== undefined) {
Expand Down Expand Up @@ -123,10 +124,16 @@ describe('submitVote', () => {
test('returns false when request is aborted', async () => {
const controller = new AbortController();
controller.abort();
// Stub fetch: undici leaks an unhandled rejection for a pre-aborted multi-field FormData body.
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockRejectedValue(controller.signal.reason);

const result = await submitVote(actionUrl, formData, controller.signal);

expect(result).toBe(false);
expect(fetchSpy).toHaveBeenCalledWith(
actionUrl,
expect.objectContaining({ signal: controller.signal }),
);
});
});
});
Expand Down
Loading