Skip to content

Commit

Permalink
feat(Dialog): throw Error when occur in onOk
Browse files Browse the repository at this point in the history
  • Loading branch information
bojoyzhou authored and tao1991123 committed Jan 8, 2019
1 parent 75b01ea commit 35e1a9a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/dialog/show.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ class Modal extends Component {
if (result !== false) {
callback();
}
}).catch(() => {
}).catch((e) => {
this.loading(false);
throw e;
});
} else if (res !== false) {
callback();
Expand Down
39 changes: 36 additions & 3 deletions test/dialog/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe('inner', () => {
content: 'Content',
animation: false
});
assert(hasClass(document.querySelector('.next-dialog-message.next-message.next-addon.next-large'), 'next-message-help')); assert(!document.querySelector('.next-dialog-header'));
assert(hasClass(document.querySelector('.next-dialog-message.next-message.next-addon.next-large'), 'next-message-help')); assert(!document.querySelector('.next-dialog-header'));
assert(document.querySelector('.next-message-title').textContent.trim() === 'Title');
assert(document.querySelector('.next-message-content').textContent.trim() === 'Content');
const btns = document.querySelectorAll('.next-dialog-btn');
Expand Down Expand Up @@ -300,7 +300,6 @@ describe('inner', () => {
});
}
});

ReactTestUtils.Simulate.click(document.querySelector('.next-btn-primary'));

setTimeout(() => {
Expand Down Expand Up @@ -348,7 +347,7 @@ describe('inner', () => {
cancel: 'near cancel'
}
}}>
<Demo locale={{ok: 'my ok'}} animation={false} />
<Demo locale={{ ok: 'my ok' }} animation={false} />
</ConfigProvider>
</ConfigProvider>
);
Expand Down Expand Up @@ -415,6 +414,40 @@ describe('inner', () => {

assert(!document.querySelector('.far-overlay-wrapper'));
});

it('should throw error (async)', () => {
const { hide } = Dialog.show({
title: 'Title',
content: 'Content',
onOk: async () => {
throw Error();
}
});
try {
ReactTestUtils.Simulate.click(document.querySelector('.next-btn-primary'));
assert(false);
} catch (e) {
assert(true);
}
hide();
});

it('should throw error', () => {
const { hide } = Dialog.show({
title: 'Title',
content: 'Content',
onOk: () => {
throw Error();
}
});
try {
ReactTestUtils.Simulate.click(document.querySelector('.next-btn-primary'));
assert(false);
} catch (e) {
assert(true);
}
hide();
});
});

function assertOkBtn(btn) {
Expand Down

0 comments on commit 35e1a9a

Please sign in to comment.