Angular2 RC5 Mock Activated Route Params

后端 未结 2 1573
庸人自扰
庸人自扰 2020-12-16 00:46

I need to be able to mock the activated route parameters to be able to test my component.

Here\'s my best attempt so far, but it doesn\'t work.

{ pro         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 01:20

    Your mock must reflect the object it's replacing. You .subscribe because it returns an observable, not just the object, so your mock value should too:

    import { Observable } from 'rxjs/Rx';
    
    ...
    
    { provide: ActivatedRoute, useValue: { 'params': Observable.from([{ 'id': 1 }]) } }
    

提交回复
热议问题