I'm new to unit testing in the context of an Angular 5 application. And right now, I'm trying to unit test a basic component.
The component is called CardComponent, and within the HTML of this component, I call the CheckboxComponent.
So here's the HTML of the CardComponent:
<div>
<p>Test</p>
<jg-checkbox [label]="'Test label'"></jg-checkbox>
</div>
As you can see, there's nothing complicated going on.
However, the CheckboxComponent does inject a service. For the sake of this question, I'll just call it TestService.
So when I unit test my CardComponent, here's my testbed:
TestBed.configureTestingModule({
declarations: [
CheckboxComponent
]
}).compileComponents();
Then I run this test:
it('should create', () => {
expect(component).toBeTruthy();
});
This is just the default test that gets created through the CLI.
But now, it complains that there's no provider for the TestService. Am I really supposed to inject (and mock/spy) that as well?
That seems a bit backwards because I only care about the CardComponent, I shouldn't have to care about the CheckboxComponent, right? That's the whole point of unit testing.
Otherwise, since Angular has hierarchical components, I might have to go down many levels deep as my app grows.
This can't be right.
Can someone please help with this issue? I appreciate the help!