How to unit test a Angular 4 component which uses router.paramMap

后端 未结 5 876
星月不相逢
星月不相逢 2021-02-19 05:48

I m new to angular 4 and trying to test one of the angular 4 feature router.paramMap from unit tests, Reading route params in fallowing way and working as expected in my applica

5条回答
  •  旧巷少年郎
    2021-02-19 06:06

    I am using a slightly different method of getting the params in my component:

    this.id = this.route.snapshot.paramMap.get('id');
    

    And this is what worked for me in the jasmine test:

    {
          provide: ActivatedRoute,
          useValue: {
            snapshot: {
              paramMap: convertToParamMap({id: 1})
            }
          }
    }
    

提交回复
热议问题