Skip to content

Commit

Permalink
fix: test error
Browse files Browse the repository at this point in the history
  • Loading branch information
aojunhao123 committed Jan 9, 2025
1 parent 7e3eecf commit cf03f2b
Showing 1 changed file with 9 additions and 52 deletions.
61 changes: 9 additions & 52 deletions tests/SubMenu.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,61 +364,17 @@ describe('SubMenu', () => {
});

describe('undefined key', () => {
it('warning item', () => {
resetWarned();
const errorSpy = jest
.spyOn(console, 'error')
.mockImplementation(() => {});

render(
<Menu
items={[
{
label: '1',
type: 'item',
key: undefined,
},
]}
/>,
);

expect(errorSpy).toHaveBeenCalledWith(
'Warning: MenuItem should not leave undefined `key`.',
);

errorSpy.mockRestore();
});

it('warning sub menu', () => {
resetWarned();
const errorSpy = jest
.spyOn(console, 'error')
.mockImplementation(() => {});

render(
<Menu
items={[
{
type: 'submenu',
key: undefined,
children: [],
},
]}
/>,
);

expect(errorSpy).toHaveBeenCalledWith(
'Warning: SubMenu should not leave undefined `key`.',
);

errorSpy.mockRestore();
});

it('should not warning', () => {
resetWarned();
const errors: any[] = [];
const errorSpy = jest
.spyOn(console, 'error')
.mockImplementation(() => {});
.mockImplementation((msg, ...args) => {
// Only collect non-act related warnings
if (!msg.includes('act(...)')) {
errors.push([msg, ...args]);
}
});

render(
<Menu
Expand All @@ -430,7 +386,8 @@ describe('SubMenu', () => {
/>,
);

expect(errorSpy).not.toHaveBeenCalled();
// Check if there are any non-act related warnings
expect(errors).toHaveLength(0);
errorSpy.mockRestore();
});
});
Expand Down

0 comments on commit cf03f2b

Please sign in to comment.