dimanche 18 mars 2018

Create fake routes to test component's link-to

I have a component that gets menu items and renders navbar. So now I'm writing integration test, and I want to make sure, that component renders right links and labels. First of all, I added router initialization to make link-to display href prop:

moduleForComponent('main-menu', 'Integration | Component | main menu', 
{
  integration: true,
  setup() {
    const router = getOwner(this).lookup('router:main');
    router.setupRouter();
  }
});

Now I want to create some fake routes to test component, and to be independent from application router's setup. So I try to use map function:

moduleForComponent('main-menu', 'Integration | Component | main menu', {
  integration: true,
  beforeEach() {
    const router = getOwner(this).lookup('router:main');
    router.map(function() {
      this.route('link1');
      this.route('link2');
    });
    router.setupRouter();
  }
});

And I get Promise rejected before "it renders": router.map is not a function. Has anyone had experience in this?




Aucun commentaire:

Enregistrer un commentaire