How to mock route.snapshot.params?

后端 未结 2 1738
执念已碎
执念已碎 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 10:16

    Ok, I've found how to mock ActivatedRoute snapshot in the simple way. Something like this works for me:

    providers: [MyComponent, {
      provide: ActivatedRoute,
      useValue: {snapshot: {params: {'myId': '123'}}}
    }
    

    Thanks :)

提交回复
热议问题