mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
fix(jest): fix segfault when passing jest.fn into another jest.fn (#7507)
Close: #5900
This commit is contained in:
@@ -280,6 +280,8 @@ public:
|
||||
if (lengthJSValue.isNumber()) {
|
||||
this->putDirect(vm, vm.propertyNames->length, (lengthJSValue), JSC::PropertyAttribute::DontEnum | JSC::PropertyAttribute::ReadOnly);
|
||||
}
|
||||
} else if (auto* fn = jsDynamicCast<JSMockFunction*>(value)) {
|
||||
nameToUse = fn->get(global, vm.propertyNames->name).toWTFString(global);
|
||||
} else if (auto* fn = jsDynamicCast<InternalFunction*>(value)) {
|
||||
nameToUse = fn->name();
|
||||
} else {
|
||||
|
||||
@@ -620,6 +620,21 @@ describe("mock()", () => {
|
||||
expect(fn).toHaveBeenNthCalledWith(5, 1, undefined);
|
||||
expect(fn).not.toHaveBeenNthCalledWith(5, 1);
|
||||
});
|
||||
|
||||
it("no segmentation fault when passing jest.fn into another jest.fn, issue#5900", () => {
|
||||
function foo() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function bar(fn = jest.fn(foo)) {
|
||||
expect(fn.getMockName()).toBe("foo");
|
||||
let newFn = jest.fn(fn);
|
||||
expect(newFn.getMockName()).toBe("foo");
|
||||
return newFn;
|
||||
}
|
||||
|
||||
expect(bar()()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("spyOn", () => {
|
||||
|
||||
Reference in New Issue
Block a user