0

I'm trying to test the code that sets a page title depending on the activated route in a component.

//  Title Map
 pageTitleMap = {
    page1: "Page 1",
    page2: "Page 2"
  }

//  Method to be tested
 setPageTitle() {
    this._Activatedroute.url.subscribe((urlPath) => {     
      const parentPath = urlPath[0].path;
      this.pageTitle = `${this.pageTitleMap[parentPath]} - TITLE`;
    })
  }

it('should set page title depending on URL path', () => {
    //  How do I test the code in setPageTitle?
});
Vega
  • 27,856
  • 27
  • 95
  • 103
  • 1
    Does this answer your question? [How to unit test a component that depends on parameters from ActivatedRoute?](https://stackoverflow.com/questions/38356084/how-to-unit-test-a-component-that-depends-on-parameters-from-activatedroute) It's not identical, but the approach is the same – Drenai Jun 26 '22 at 12:54
  • 2
    what is _Activatedroute ? Is it some custom service implemented by you or does it use ActivatedRoute from angular router? – Cristian-Florin Calina Jun 26 '22 at 12:58
  • please post complete code for unit under test. –  Jun 26 '22 at 13:03
  • Drenai - I will take a look at that post. Thank you! Cristian - _ActivatedRoute is _Activated Route: ActivatedRoute (from Angular Router) E Maggini, I will post complete code. thank you! – Sandeep Barnabas Jun 27 '22 at 16:07

0 Answers0