mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 20:39:05 +00:00
## Summary - Fixes missing Jest API functions that were marked as implemented but undefined - Adds `jest.mock()` to the jest object (was missing despite being marked as ✅) - Adds `jest.resetAllMocks()` to the jest object (implemented as alias to clearAllMocks) - Adds `vi.mock()` to the vi object for Vitest compatibility ## Test plan - [x] Added regression test in `test/regression/issue/issue-1825-jest-mock-functions.test.ts` - [x] Verified `jest.mock("module", factory)` works correctly - [x] Verified `jest.resetAllMocks()` doesn't throw and is available - [x] Verified `mockReturnThis()` returns the mock function itself - [x] All tests pass ## Related Issue Fixes discrepancies found in #1825 where these functions were marked as working but were actually undefined. 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
30 lines
907 B
TypeScript
30 lines
907 B
TypeScript
import { describe, expect, jest, test } from "bun:test";
|
|
|
|
describe("Jest mock functions from issue #1825", () => {
|
|
test("jest.mock should be available and work with factory function", () => {
|
|
// Should not throw - jest.mock should be available
|
|
expect(() => {
|
|
jest.mock("fs", () => ({ readFile: jest.fn() }));
|
|
}).not.toThrow();
|
|
});
|
|
|
|
test("jest.resetAllMocks should be available and not throw", () => {
|
|
const mockFn = jest.fn();
|
|
mockFn();
|
|
expect(mockFn).toHaveBeenCalledTimes(1);
|
|
|
|
// Should not throw - jest.resetAllMocks should be available
|
|
expect(() => {
|
|
jest.resetAllMocks();
|
|
}).not.toThrow();
|
|
});
|
|
|
|
test("mockReturnThis should return the mock function itself", () => {
|
|
const mockFn = jest.fn();
|
|
const result = mockFn.mockReturnThis();
|
|
|
|
// mockReturnThis should return the mock function itself
|
|
expect(result).toBe(mockFn);
|
|
});
|
|
});
|