How to mock route.snapshot.params?

后端 未结 2 1736
执念已碎
执念已碎 2021-02-02 09:21

In my Angular 4 component I have something like:

constructor(private route: ActivatedRoute) {
}

ngOnInit() {
  this.myId          


        
2条回答
  •  清酒与你
    2021-02-02 09:55

    If using route.snapshot.paramMap.get( 'uuid' ) instead:

    import { ActivatedRoute, convertToParamMap } from '@angular/router';
    
    {
        provide: ActivatedRoute, useValue:
            { snapshot: { paramMap: convertToParamMap( { 'uuid': '99-88-77' } ) } }
    }
    

提交回复
热议问题