Skip to content

Commit 783a9e7

Browse files
authored
Unit test callback crashing fix
1 parent c1b78ca commit 783a9e7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/SubMenu.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,19 @@ describe('<SubMenu/>', () => {
4242
await user.hover(wrapper);
4343
await expect(() => waitForMenuVisible(submenu)).rejects.toThrow();
4444
});
45+
46+
it('should not crash after immediate unmount', async () => {
47+
let callback = null;
48+
jest.spyOn(window, 'requestAnimationFrame').mockImplementation((cb) => {
49+
callback = cb;
50+
return 1;
51+
});
52+
const { unmount } = render(<SubMenu title='Title' hoverDelay={0} />);
53+
const user = userEvent.setup();
54+
const wrapper = screen.getByText('Title');
55+
await user.hover(wrapper);
56+
unmount();
57+
58+
expect(callback).not.toThrow();
59+
});
4560
});

0 commit comments

Comments
 (0)