import { fireEvent, render, screen, waitFor } from '@testing-library/react' import { CalendarDateInput } from '@/components/admin/DataStatisticsTab' describe('CalendarDateInput', () => { test('稳定日期值不会触发重复渲染,并会在日期变化时同步月份', async () => { const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => undefined) try { const { rerender } = render( , ) fireEvent.click(screen.getByRole('button', { name: '打开开始日期日历' })) expect(screen.getByText('2026年08月')).toBeInTheDocument() rerender( , ) await waitFor(() => { expect(screen.getByText('2026年07月')).toBeInTheDocument() }) expect(consoleErrorSpy.mock.calls.flat().join(' ')).not.toContain('Maximum update depth exceeded') } finally { consoleErrorSpy.mockRestore() } }) })