Skip to content
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

Closed
kamok opened this issue Dec 1, 2016 · 3 comments
Closed

How can I test simple navigation with this set up? #184

kamok opened this issue Dec 1, 2016 · 3 comments

Comments

@kamok
Copy link

kamok commented Dec 1, 2016

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.

@lathonez
Copy link
Owner

lathonez commented Dec 2, 2016 via email

@kamok kamok closed this as completed Dec 2, 2016
@kamok
Copy link
Author

kamok commented Dec 2, 2016

Thanks. I got feedback from another engineer on this. You're correct.

@lathonez
Copy link
Owner

#191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants