mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-09 02:49:18 +08:00
This reverts commit 2b12ef528d.
This commit is contained in:
@@ -98,22 +98,8 @@ const ActionButton: React.FC<ActionButtonProps> = (props) => {
|
||||
return;
|
||||
}
|
||||
let returnValueOfOnOk: PromiseLike<any>;
|
||||
// Currently only Popconfirm passes `emitEvent` as true
|
||||
if (emitEvent) {
|
||||
// if actionFn has been throw error, just reset clickedRef
|
||||
try {
|
||||
returnValueOfOnOk = actionFn(e);
|
||||
} catch (error) {
|
||||
clickedRef.current = false;
|
||||
|
||||
// Log error for debugging unless in silent mode
|
||||
if (!isSilent?.()) {
|
||||
console.error('Error in actionFn:', error);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
returnValueOfOnOk = actionFn(e);
|
||||
if (quitOnNullishReturnValue && !isThenable(returnValueOfOnOk)) {
|
||||
clickedRef.current = false;
|
||||
onInternalClose(e);
|
||||
|
||||
@@ -407,119 +407,4 @@ describe('Popconfirm', () => {
|
||||
expect(popconfirmElement).toHaveStyle({ padding: '20px' });
|
||||
expect(popconfirmBodyElement).toHaveStyle({ padding: '10px' });
|
||||
});
|
||||
|
||||
it('should allow retry after onConfirm throws synchronous error', async () => {
|
||||
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
let callCount = 0;
|
||||
const onConfirm = jest.fn(() => {
|
||||
callCount += 1;
|
||||
if (callCount === 1) {
|
||||
throw new Error('Test synchronous error');
|
||||
}
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
const { container } = render(
|
||||
<Popconfirm title="Are you sure?" onConfirm={onConfirm}>
|
||||
<Button className="trigger">Delete</Button>
|
||||
</Popconfirm>,
|
||||
);
|
||||
|
||||
const triggerNode = container.querySelector('.trigger')!;
|
||||
|
||||
// Open popconfirm
|
||||
fireEvent.click(triggerNode);
|
||||
await waitFakeTimer();
|
||||
|
||||
const okButton = container.querySelector('.ant-btn-primary')!;
|
||||
|
||||
// First click - should throw error
|
||||
fireEvent.click(okButton);
|
||||
await waitFakeTimer();
|
||||
|
||||
expect(onConfirm).toHaveBeenCalledTimes(1);
|
||||
expect(consoleErrorSpy).toHaveBeenCalledWith('Error in actionFn:', expect.any(Error));
|
||||
|
||||
// Popconfirm should still be open after error
|
||||
expect(container.querySelector('.ant-popover')).toBeTruthy();
|
||||
|
||||
// Second click - should succeed
|
||||
fireEvent.click(okButton);
|
||||
await waitFakeTimer();
|
||||
|
||||
expect(onConfirm).toHaveBeenCalledTimes(2);
|
||||
|
||||
consoleErrorSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('should not log error when onConfirm throws error in silent mode', async () => {
|
||||
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
const onConfirm = jest.fn(() => {
|
||||
throw new Error('Test error in silent mode');
|
||||
});
|
||||
|
||||
// Create a wrapper component that simulates silent mode
|
||||
const TestComponent = () => {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
|
||||
return (
|
||||
<Popconfirm title="Are you sure?" onConfirm={onConfirm} open={open} onOpenChange={setOpen}>
|
||||
<Button className="trigger">Delete</Button>
|
||||
</Popconfirm>
|
||||
);
|
||||
};
|
||||
|
||||
const { container } = render(<TestComponent />);
|
||||
|
||||
const triggerNode = container.querySelector('.trigger')!;
|
||||
|
||||
// Open popconfirm
|
||||
fireEvent.click(triggerNode);
|
||||
await waitFakeTimer();
|
||||
|
||||
const okButton = container.querySelector('.ant-btn-primary')!;
|
||||
|
||||
// Click OK button - should throw error but not log in normal case
|
||||
fireEvent.click(okButton);
|
||||
await waitFakeTimer();
|
||||
|
||||
expect(onConfirm).toHaveBeenCalledTimes(1);
|
||||
// In current implementation, error should be logged
|
||||
expect(consoleErrorSpy).toHaveBeenCalled();
|
||||
|
||||
consoleErrorSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('should reset button loading state after synchronous error', async () => {
|
||||
const onConfirm = jest.fn(() => {
|
||||
throw new Error('Synchronous error');
|
||||
});
|
||||
|
||||
const { container } = render(
|
||||
<Popconfirm title="Are you sure?" onConfirm={onConfirm}>
|
||||
<Button className="trigger">Delete</Button>
|
||||
</Popconfirm>,
|
||||
);
|
||||
|
||||
const triggerNode = container.querySelector('.trigger')!;
|
||||
|
||||
// Open popconfirm
|
||||
fireEvent.click(triggerNode);
|
||||
await waitFakeTimer();
|
||||
|
||||
const okButton = container.querySelector('.ant-btn-primary')! as HTMLButtonElement;
|
||||
|
||||
// Click OK button - should throw error
|
||||
fireEvent.click(okButton);
|
||||
await waitFakeTimer();
|
||||
|
||||
// Button should not be in loading state after error
|
||||
expect(okButton.querySelector('.ant-btn-loading-icon')).toBeFalsy();
|
||||
|
||||
// Should be able to click again
|
||||
fireEvent.click(okButton);
|
||||
await waitFakeTimer();
|
||||
|
||||
expect(onConfirm).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user