Skip to content

fix(bun:test): return an object when a mock function is constructed with new#31386

Open
robobun wants to merge 10 commits into
mainfrom
farm/4e0236f3/mock-construct-return-object
Open

fix(bun:test): return an object when a mock function is constructed with new#31386
robobun wants to merge 10 commits into
mainfrom
farm/4e0236f3/mock-construct-return-object

Merge remote-tracking branch 'origin/main' into farm/4e0236f3/mock-co…

47f6d47
Select commit
Loading
Failed to load commit list.
Claude / Claude Code Review completed May 31, 2026 in 11m 54s

Code review found 1 potential issue

Found 1 candidates, confirmed 1. See review comments for details.

Details

Severity Count
🔴 Important 0
🟡 Nit 0
🟣 Pre-existing 1
Severity File:Line Issue
🟣 Pre-existing src/jsc/bindings/JSMockFunction.cpp:1015-1017 Mock functions lack a default .prototype, so instanceof throws on constructed instances

Annotations

Check notice on line 1017 in src/jsc/bindings/JSMockFunction.cpp

See this annotation in the file changed.

@claude claude / Claude Code Review

Mock functions lack a default .prototype, so instanceof throws on constructed instances

Pre-existing nit, not a regression: `JSMockFunction` never installs a `.prototype` own-property (InternalFunction doesn't auto-create one, unlike JSFunction), so `jest.fn().prototype` is `undefined`. With construct now actually working, the default case `const fn = jest.fn(); (new fn()) instanceof fn` throws `TypeError: instanceof called on an object with an invalid prototype property`, and `Object.getPrototypeOf(new fn())` is `Object.prototype` rather than `fn.prototype` — both diverge from Jes