-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I test simple navigation with this set up? #184
Comments
I am away at the moment so can't answer in detail. Just spy on
instance.nav.pop and check that it was called?
This question has nothing to do with "this setup", is more of a "how to
unit test" question. You'll get a much better response on stack overflow.
…On 1 Dec 2016 22:17, "Ka Mok" ***@***.***> wrote:
Thanks for writing this seed project for testing. I'm currently still
learning Ionic 2 and Angular, so this might be an elementary question: How
do I test a simple nav.pop(); button?
I have a very simple button that calls a 'goBack()' function when clicked:
@component({
selector: 'back-button',
template: `
<button ion-button icon-only clear color="light" (click)="goBack()">
<ion-icon name="arrow-back"></ion-icon>
</button>
`
})
export class BackButton {
constructor(public navCtrl: NavController, public viewCtrl: ViewController) {}
goBack(): void {
this.navCtrl.pop();
}
}
In the tests, I have these expectations:
describe('BackButton', () => {
beforeEach(async(() => TestUtils.beforeEachCompiler([BackButton]).then(compiled => {
fixture = compiled.fixture;
instance = compiled.instance;
// instance.ViewController = new ViewControllerMock();
})));
afterEach(() => {
fixture.destroy();
});
it('initializes', () => {
expect(instance).not.toBeNull();
});
it('goes back a page when pressed', () => {
fixture.detectChanges();
spyOn(instance,'goBack');
TestUtils.eventFire(fixture.nativeElement.querySelectorAll('button')[0], 'click');
expect(instance.goBack).toHaveBeenCalled();
});
});
This is all pretty much what you have in the clicker app, but I think the
last expectation doesn't really test if nav.pop is triggered, and I don't
know the convention of doing so. Please assist if possible.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#184>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AG5tSPf5TYVRzngETY_iVP4FLBjQkd9_ks5rDuUKgaJpZM4LBgrT>
.
|
Thanks. I got feedback from another engineer on this. You're correct. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for writing this seed project for testing. I'm currently still learning Ionic 2 and Angular, so this might be an elementary question: How do I test a simple
nav.pop();
button?I have a very simple button that calls a 'goBack()' function when clicked:
In the tests, I have these expectations:
This is all pretty much what you have in the clicker app, but I think the last expectation doesn't really test if
nav.pop
is triggered, and I don't know the convention of doing so. Please assist if possible.The text was updated successfully, but these errors were encountered: