Skip to content

Commit

Permalink
fix(navigation): move onWillDismiss and onDidDismiss, add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbryan9 authored and brandyscarney committed Sep 23, 2016
1 parent 963e835 commit e26c425
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
34 changes: 33 additions & 1 deletion src/navigation/test/view-controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mockView } from '../../util/mock-providers';
import { mockNavController, mockView, mockViews } from '../../util/mock-providers';


describe('ViewController', () => {
Expand Down Expand Up @@ -87,6 +87,38 @@ describe('ViewController', () => {
}, 10000);
});

describe('willDismiss', () => {
it('should have data in the willDismiss', (done) => {
// arrange
let viewController = mockView();
let navControllerBase = mockNavController();
mockViews(navControllerBase, [viewController]);

viewController.onWillDismiss((data: any) => {
expect(data).toEqual('willDismiss data');
done();
});

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

describe('didDismiss', () => {
it('should have data in the didDismiss', (done) => {
// arrange
let viewController = mockView();
let navControllerBase = mockNavController();
mockViews(navControllerBase, [viewController]);

viewController.onDidDismiss((data: any) => {
expect(data).toEqual('didDismiss data');
done();
});

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

afterEach(() => {
if (subscription) {
subscription.unsubscribe();
Expand Down
4 changes: 2 additions & 2 deletions src/navigation/view-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class ViewController {
this._onWillDismiss && this._onWillDismiss(data, role);
return this._nav.remove(this._nav.indexOf(this), 1, options).then(() => {
this._onDidDismiss && this._onDidDismiss(data, role);
this._onWillDismiss = null;
this._onDidDismiss = null;
return data;
});
}
Expand Down Expand Up @@ -515,7 +515,7 @@ export class ViewController {
}
}

this._nav = this._cmp = this.instance = this._cntDir = this._cntRef = this._hdrDir = this._ftrDir = this._nb = this._onDidDismiss = null;
this._nav = this._cmp = this.instance = this._cntDir = this._cntRef = this._hdrDir = this._ftrDir = this._nb = this._onWillDismiss = null;
}

/**
Expand Down

0 comments on commit e26c425

Please sign in to comment.