Fix: Print reject error when ActionButton catch promise rejects

This commit is contained in:
Jason 2019-05-09 12:24:59 +08:00
parent 6d845f60ef
commit db5da92f0c
2 changed files with 16 additions and 1 deletions

View File

@ -56,7 +56,9 @@ export default class ActionButton extends React.Component<ActionButtonProps, Act
// this.setState({ loading: false });
closeModal(...args);
},
() => {
(e: Error) => {
// Emit error when catch promise reject
console.error(e);
// See: https://github.com/ant-design/ant-design/issues/6183
this.setState({ loading: false });
},

View File

@ -67,6 +67,19 @@ describe('Modal.confirm triggers callbacks correctly', () => {
expect(errorSpy).not.toHaveBeenCalled();
});
it('should emit error when onOk return Promise.reject', () => {
const error = new Error('something wrong');
open({
onOk: () => Promise.reject(error),
});
// Fifth Modal
$$('.ant-btn-primary')[0].click();
// wait promise
return Promise.resolve().then(() => {
expect(errorSpy).toHaveBeenCalledWith(error);
});
});
if (process.env.REACT !== '15') {
it('shows animation when close', () => {
jest.useFakeTimers();