Template parse error in Jasmine test but not actual app
Well, the module of your test only has MiddleRowComponent declared. So it doesn't know about CircleComponent:
TestBed.configureTestingModule({
declarations: [MiddleRowComponent], // declare the test component
})
Add all the necessary components in the declarations of the testing module, or add LandingPageModule
to the imports of the testing module.
Another option is to add the NO_ERRORS_SCHEMA schema to the test setup. Any unrecognised components will now not cause an error. I use this a lot when working with third party modules like Angular Material Design.
import { NO_ERRORS_SCHEMA } from '@angular/core';
...
beforeEach(
async(() => {
TestBed.configureTestingModule({
declarations: [MiddleRowComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
})
);
I had a similar problem and found this page, and while JB Nizet's answer led to a solution for me, it didn't work for me as-is. I'm not trying to take away from his solid answer to the original question, just trying to help the next person who comes along.
My problem was exactly like the OP's, except that my custom component (MiddleRowComponent
in this example) used a third-party component. The unit test error was given about the third-party tag used in my template, even though it worked just fine in the actual app. The solution for me was to also include an imports
for the third-party in my testing module:
TestBed.configureTestingModule({
declarations: [MiddleRowComponent],
imports: [TheThirdPartyModule]
})
Then my unit tests ran without the error. Hope that helps!