Con esto se genera prácticas del render a los componentes que ya están en un routing que reciben esos parámetros mediante un mock
product-detail.component.spec.ts
it('should show the product in the view', () => {
const productId = '2';
route.setParamMap({id: productId});
const productMock = {
...generateOneProduct(),
id: productId,
}
productsService.getOne.and.returnValue(mockObservable(productMock));
fixture.detectChanges(); // ngOnInit
const titleText = getText(fixture, 'title');
const priceText = getText(fixture, 'price');
expect(titleText).toContain(productMock.title);
expect(priceText).toContain(productMock.price);
expect(productsService.getOne).toHaveBeenCalledWith(productId);
});
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?
o inicia sesión.