I'm relatively new to Angular and I'm trying to get my code to pass a unit test, It's currently failing with this error.
TypeError: Cannot read properties of undefined (reading 'value')
Here's my simple method, currently want to set visible to true if a company user has a driving license, and false if they don't. I don't think the unit test code is of any value since none of it works, but I've tried methods like mockServices and using fake data/return values
hasLicense() {
this.licenseService.getLicences(
this.companyService.selectedCompany.value.companyId,
this.companyService.selectedCompany.value.userId
).subscribe(l => {
if(l.driver) {
this.visible = true;
} else {
this.visible = false;
}
});
}
CodePudding user response:
You should not test the value of the subject, it is an implementation detail. You need to test what the consumer of your class will see, in this case the visible
property.