Skip to content

Commit cf03f2b

Browse files
committed
fix: test error
1 parent 7e3eecf commit cf03f2b

File tree

1 file changed

+9
-52
lines changed

1 file changed

+9
-52
lines changed

tests/SubMenu.spec.tsx

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -364,61 +364,17 @@ describe('SubMenu', () => {
364364
});
365365

366366
describe('undefined key', () => {
367-
it('warning item', () => {
368-
resetWarned();
369-
const errorSpy = jest
370-
.spyOn(console, 'error')
371-
.mockImplementation(() => {});
372-
373-
render(
374-
<Menu
375-
items={[
376-
{
377-
label: '1',
378-
type: 'item',
379-
key: undefined,
380-
},
381-
]}
382-
/>,
383-
);
384-
385-
expect(errorSpy).toHaveBeenCalledWith(
386-
'Warning: MenuItem should not leave undefined `key`.',
387-
);
388-
389-
errorSpy.mockRestore();
390-
});
391-
392-
it('warning sub menu', () => {
393-
resetWarned();
394-
const errorSpy = jest
395-
.spyOn(console, 'error')
396-
.mockImplementation(() => {});
397-
398-
render(
399-
<Menu
400-
items={[
401-
{
402-
type: 'submenu',
403-
key: undefined,
404-
children: [],
405-
},
406-
]}
407-
/>,
408-
);
409-
410-
expect(errorSpy).toHaveBeenCalledWith(
411-
'Warning: SubMenu should not leave undefined `key`.',
412-
);
413-
414-
errorSpy.mockRestore();
415-
});
416-
417367
it('should not warning', () => {
418368
resetWarned();
369+
const errors: any[] = [];
419370
const errorSpy = jest
420371
.spyOn(console, 'error')
421-
.mockImplementation(() => {});
372+
.mockImplementation((msg, ...args) => {
373+
// Only collect non-act related warnings
374+
if (!msg.includes('act(...)')) {
375+
errors.push([msg, ...args]);
376+
}
377+
});
422378

423379
render(
424380
<Menu
@@ -430,7 +386,8 @@ describe('SubMenu', () => {
430386
/>,
431387
);
432388

433-
expect(errorSpy).not.toHaveBeenCalled();
389+
// Check if there are any non-act related warnings
390+
expect(errors).toHaveLength(0);
434391
errorSpy.mockRestore();
435392
});
436393
});

0 commit comments

Comments
 (0)