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

后端 未结 5 863
星月不相逢
星月不相逢 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:07

    Your code has a problem, in order to get a param from the URL, you have to write things in a different way.

    constructor(private router:Router, private actRoute:ActivatedRoute) {
    }
    
    ngOnInit() {
        this.router.paramMap
            .switchMap((params: ParamMap) => {
                params.get(id);
                ....
            })
            .subscribe((....) => {
                ....
            })
    }
    

提交回复
热议问题