Reputation: 73
I am trying to test a component in Angular using Jasmine. the test is simple, it just needs to verify that the component is created.
it('AppComponent should be created', () => {
expect(component).toBeTruthy();
});
It is a default spec which is created automatically inside spec file if you use angular cli. My problem is that the html file of the component has some elements that are not regular tags, that is custom.
<app-header></app-header>
The question is how can I let Jasmine know about them, where they came from, or how to add links etc, so that errors like
Failed: Template parse errors: 'app-header' is not a known element: 1. If 'app-header' is an Angular component, then verify that it is part of this module.
won't show up in Karma debug page. How to verify?
Upvotes: 4
Views: 2229
Reputation: 61
It might work if you add NO_ERRORS_SCHEMA :
import { NO_ERRORS_SCHEMA } from '@angular/core';
which would ignore those component errors
Upvotes: 2
Reputation: 151
You are not setting up your TestBed.configureTestingModule({}
block correctly. It is structured like a module in angular. You need to import and inject your modules/components/services and so on here. Or mock them.
Please read a tutorial on this (https://angular.io/guide/testing#test-a-component). As this is very basic and couldn't be explained in a single answer here.
Upvotes: 1