mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 11:39:28 +08:00
test: add test case
This commit is contained in:
parent
2b42bd1664
commit
d7cc34f9d8
@ -372,7 +372,7 @@ describe('Modal.hook', () => {
|
||||
it('should be applied correctly locale', async () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
const Demo = ({ count }: { count: number }) => {
|
||||
const Demo: React.FC<{ count: number }> = ({ count }) => {
|
||||
React.useEffect(() => {
|
||||
const instance = Modal.confirm({});
|
||||
return () => {
|
||||
@ -409,4 +409,45 @@ describe('Modal.hook', () => {
|
||||
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('support await', async () => {
|
||||
jest.useFakeTimers();
|
||||
|
||||
let notReady = true;
|
||||
let lastResult: boolean | null = null;
|
||||
|
||||
const Demo: React.FC = () => {
|
||||
const [modal, contextHolder] = Modal.useModal();
|
||||
|
||||
React.useEffect(() => {
|
||||
(async () => {
|
||||
lastResult = await modal.confirm({
|
||||
content: <Input />,
|
||||
onOk: async () => {
|
||||
if (notReady) {
|
||||
notReady = false;
|
||||
return Promise.reject();
|
||||
}
|
||||
},
|
||||
});
|
||||
})();
|
||||
}, []);
|
||||
|
||||
return contextHolder;
|
||||
};
|
||||
|
||||
render(<Demo />); // Wait for modal show
|
||||
|
||||
await waitFakeTimer(); // First time click should not close
|
||||
|
||||
fireEvent.click(document.querySelector('.ant-btn-primary')!);
|
||||
await waitFakeTimer();
|
||||
expect(lastResult).toBeFalsy(); // Second time click to close
|
||||
|
||||
fireEvent.click(document.querySelector('.ant-btn-primary')!);
|
||||
await waitFakeTimer();
|
||||
expect(lastResult).toBeTruthy();
|
||||
|
||||
jest.useRealTimers();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user