Skip to content

Commit

Permalink
fix(view-controller): dismiss does not crash when called more than once
Browse files Browse the repository at this point in the history
fixes #8395
  • Loading branch information
manucorporat committed Oct 2, 2016
1 parent 2bc4df8 commit d5f71a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/navigation/test/view-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,26 @@ describe('ViewController', () => {

viewController.dismiss('didDismiss data');
}, 10000);

it('should not crash when calling dismiss() twice', (done) => {
// arrange
let viewController = mockView();
let navControllerBase = mockNavController();
mockViews(navControllerBase, [viewController]);

viewController.onDidDismiss((data: any) => {
expect(data).toEqual('didDismiss data');
setTimeout(() => {
viewController.dismiss(); // it should not crash
done();
}, 100);
});

viewController.dismiss('didDismiss data');
}, 10000);
});


afterEach(() => {
if (subscription) {
subscription.unsubscribe();
Expand Down
4 changes: 4 additions & 0 deletions src/navigation/view-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ export class ViewController {
*
*/
dismiss(data?: any, role?: any, navOptions: NavOptions = {}) {
if (!this._nav) {
return Promise.resolve(false);
}

let options = merge({}, this._leavingOpts, navOptions);
this._onWillDismiss && this._onWillDismiss(data, role);
return this._nav.remove(this._nav.indexOf(this), 1, options).then(() => {
Expand Down

0 comments on commit d5f71a4

Please sign in to comment.