Therefore in the test, we need to create the mockActivatedRoute
here the targetVariable, targetVariableRate are the actual variables called by the service through the ActivatedRoute, and here the activatedRouted is activated through the sampleId . Here the sampleDATADto is the data interface adopted inside the sampleService.
then it needs to be added into the provides, cause the mockActivatedRoute replaces ActivatedRoute in this test, added inside the beforeEach, after the imports
generally speaking, in the expect would be like this
expect(routerSpy.navigate).toHaveBeenCalledWith([
... // here should be identical with the date inside the component.ts
], {
relativeTo: mockActicatedRoute, // depends whether there is such statement inside component.ts
});
ActivatedRoute normally used together with service,
it passes data through URL to the UI, take the interface here as references.
1
Therefore in the test, we need to create the
mockActivatedRoute
here the targetVariable, targetVariableRate are the actual variables called by the service through the ActivatedRoute, and here the activatedRouted is activated through thesampleId
. Here thesampleDATADto
is the data interface adopted inside thesampleService
.2
then it needs to be added into the provides, cause the mockActivatedRoute replaces ActivatedRoute in this test, added inside the beforeEach, after the
imports
3
we need to create a
spy
, to spy on the activity of theservice
, or if we need therouter
for the navigation, then we create arouterSpy
.3.1
expect
would be like this3.2
sampleServiceSpy