HTML
<ng-container *ngIf="configuration$ | async as configuration">
....
</ng-container>
TS
configuration$ : Observable<Configuration> = this.configService.configuration$;
configService.sevice.ts
private _configuration: Observable<Configuration> = this.service.loadDetails();
get configuration(): Observable<Configuration>{
return this._configuration;
}
This setup runs an api service call and fetch some configuration details from backend. let's say
{
employee_name: "SHubham",
employee_dependents: [
{name: "abc",include: true},
{name: "xyz",include: true},
{name: "ert",include: true},
]}
Now, I am trying to write test cases to check if the dependent details should be included or not for a particular employee.
How can I use mock services to validate for 2 conditions:
- if all the dependents include are true
- if all the dependents include are false/
since these data are sent from backend, how can I modify the response of api and write unit tests for them?
Here is how you can mock services in a component: https://testing-angular.com/testing-components-depending-on-services/#testing-components-depending-on-services
You can also use just an object for the mock, something like this: https://testing-angular.com/testing-components-depending-on-services/#testing-components-depending-on-services
For you, it could be: