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
You need to provide paramMap
instead of params
. paramMap
should be of type ParamMap
from @angular/router
, so normal object can be converted to ParamMap
using the method convertToParamMap()
from @angular/routing
.
You can provide the mock ActivatedRoute like below:
import { convertToParamMap} from '@angular/router';
....
.....
{
provide: ActivatedRoute,
useValue: { paramMap: Observable.of(convertToParamMap({id: 1})) }
}