import React, { useEffect } from 'react'; import { Modal } from '../..'; import { fireEvent, render, waitFakeTimer } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; import zhCN from '../zh_CN'; const Demo: React.FC<{ type: string }> = ({ type }) => { useEffect(() => { if (type === 'dashboard') { Modal.confirm({ title: 'Hello World!' }); } }, []); return null; }; describe('Locale Provider demo', () => { it('change type', async () => { jest.useFakeTimers(); const BasicExample: React.FC = () => { const [type, setType] = React.useState(''); return (
setType('about')}> about setType('dashboard')}> dashboard
{type === 'about' && ( )} {type === 'dashboard' && ( )}
); }; const { container } = render(); fireEvent.click(container.querySelector('.about')!); await waitFakeTimer(); fireEvent.click(container.querySelector('.dashboard')!); await waitFakeTimer(); expect(document.body.querySelectorAll('.ant-btn-primary span')[0]?.textContent).toBe('确 定'); Modal.destroyAll(); jest.useRealTimers(); }, 500000); });