I am trying to make unit test for my angular component but I keep getting errors about the html. For example that he doesnt know the app-create component in the test. This is for every test in every component. Even if I just want to check if 0 equals 0. Does anyone know a fix for this? or how to stop getting HTML errors
My test code:
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { CommunityListComponent } from './community-list.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { Component } from '@angular/core';
import { Subscription } from 'rxjs';
import { Community } from '../../../models/domain/Community';
import { CommunityService } from '../../../services/API/community.service';
import { CommonService } from '../../../services/common.service';
describe('CommunityListComponent', () => {
let component: CommunityListComponent;
let fixture: ComponentFixture<CommunityListComponent>;
beforeEach(async () => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, RouterTestingModule ],
declarations: [CommunityListComponent]
}).compileComponents();
fixture = TestBed.createComponent(CommunityListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('Ewa', () => {
expect(0).toEqual(0);
});
});
CodePudding user response:
You need to add the class which defines app-create-community-menu
into the imports
array.
CodePudding user response:
You can do what Matthieu suggests or you can use NO_ERRORS_SCHEMA
by doing the following:
import { NO_ERRORS_SCHEMA } from '@angular/core';
describe('CommunityListComponent', () => {
let component: CommunityListComponent;
let fixture: ComponentFixture<CommunityListComponent>;
beforeEach(async () => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, RouterTestingModule ],
declarations: [CommunityListComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
fixture = TestBed.createComponent(CommunityListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('Ewa', () => {
expect(0).toEqual(0);
});
});
NO_ERRORS_SCHEMA
says if you find anything in HTML you don't know how to render, treat is as dead HTML.