I've been struggling to write a unit test for my Angular component due to an error I can't seem to resolve. Despite my efforts to find a solution on Stack Overflow and various online documentation, I haven't had any luck yet. Here are some of the resources I've consulted:
- How to Use ActivatedRoute in Angular and Mock it in Unit Tests
- Guide to Unit Testing a Component Depending on Parameters from ActivatedRoute
- How to Properly Mock ActivatedRoute
Below, you'll find the code snippets:
.ts file
export class SomeComponent implements OnInit {
id = '--';
constructor(
private readonly someService: SomeService,
private readonly utilsService: UtilsService,
private readonly router: Router,
readonly route: ActivatedRoute,
) {}
// Methods and functionalities implementation
}
.ts.spec
class mockHttpWrapperService {
readonly isApiReady = false;
}
// Unit testing setup for SomeComponent
And here's the specific error message I'm encountering:
Chrome 93.0.4577 (Linux 0.0.0) SomeComponent should create 1 FAILED
TypeError: Cannot read properties of undefined (reading 'get')