mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 20:33:32 +08:00
fix(view-controller): dismiss does not crash when called more than once
fixes #8395
This commit is contained in:
@ -117,8 +117,26 @@ describe('ViewController', () => {
|
|||||||
|
|
||||||
viewController.dismiss('didDismiss data');
|
viewController.dismiss('didDismiss data');
|
||||||
}, 10000);
|
}, 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(() => {
|
afterEach(() => {
|
||||||
if (subscription) {
|
if (subscription) {
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
|
@ -180,6 +180,10 @@ export class ViewController {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
dismiss(data?: any, role?: any, navOptions: NavOptions = {}) {
|
dismiss(data?: any, role?: any, navOptions: NavOptions = {}) {
|
||||||
|
if (!this._nav) {
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
|
||||||
let options = merge({}, this._leavingOpts, navOptions);
|
let options = merge({}, this._leavingOpts, navOptions);
|
||||||
this._onWillDismiss && this._onWillDismiss(data, role);
|
this._onWillDismiss && this._onWillDismiss(data, role);
|
||||||
return this._nav.remove(this._nav.indexOf(this), 1, options).then(() => {
|
return this._nav.remove(this._nav.indexOf(this), 1, options).then(() => {
|
||||||
|
Reference in New Issue
Block a user