fix(jest): fix segfault when passing jest.fn into another jest.fn (#7507)

Close: #5900
This commit is contained in:
Hanaasagi
2023-12-07 16:41:31 +08:00
committed by GitHub
parent 1bf540efcf
commit dfd4b01a97
2 changed files with 17 additions and 0 deletions

View File

@@ -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", () => {