Подтвердить что ты не робот

Единичный тест Угловая с жасмином и кармой, Ошибка: не может привязываться к "xxx", так как это не известное свойство "xxxxxx".

У меня проблема с единичным тестом в угловом 5 с жасмином и кармой.

Ошибка: "Невозможно привязать к" плодам ", так как это не известное свойство" my-component2 ".

Единичный тестовый код:

SRC/приложение/компоненты/мой-component1/мой-component1.component.spec.ts:

import { TestBed, inject, ComponentFixture, async} from '@angular/core/testing';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';

import { Post } from '../../models/post.model';

import { MyComponent1Component } from './my-component1.component';
import { MyService1Service } from '../../services/my-service1.service';

import { HttpClientModule, HttpClient,HttpHandler } from '@angular/common/http';
import {fruit} from '../../Models/fruit';


fdescribe('MyComponent1Component', () => {
  let component: MyComponent1Component;
  let fixture: ComponentFixture<MyComponent1Component>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ MyComponent1Component ],
      imports: [],
      providers: [MyService1Service, HttpClient, HttpHandler, HttpTestingController]
    })

    .compileComponents();
  }));

  beforeEach(async(() => {
    fixture = TestBed.createComponent(MyComponent1Component);
    component = fixture.componentInstance;
    fixture.detectChanges();
  }));

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});
4b9b3361

Ответ 1

Вам необходимо добавить свой второй компонент при создании своего модуля тестирования, поскольку этот модуль является частью компонента 1. Если у вас нет модуля, у меня не будет my-component2, и вход будет недействительным.

TestBed.configureTestingModule({
      declarations: [ MyComponent1Component, MyComponent2Component ],
      imports: [],
      providers: [MyService1Service, HttpClient, HttpHandler, HttpTestingController]
    })

Ответ 2

Для некоторых это может помочь - иногда это может быть просто конкретный модуль, который может отсутствовать

TestBed.configureTestingModule(
{
declarations: [TestComponent],
imports: [<Specific_module>],
}